PeachParts Mercedes-Benz Forum

PeachParts Mercedes-Benz Forum (http://www.peachparts.com/shopforum/index.php)
-   Off-Topic Discussion (http://www.peachparts.com/shopforum/forumdisplay.php?f=16)
-   -   File Name Question (http://www.peachparts.com/shopforum/showthread.php?t=150882)

GottaDiesel 04-17-2006 09:34 AM

File Name Question
 
I have a script that uses a certain field to look for a file name on a server.

If the field reads: Cats

it looks for Cats.php

If the field reads: Cats and Dogs

it looks for Cats and Dogs.php

This all works like a charm and I love it.

Here's the question.

If the field reads: 3" Wide Boxes

I can't make the file called 3" Wide Boxes because it won't let me on account of the quote. Is there a way around this?

Thanks,

Pete

GottaDiesel 04-17-2006 09:52 AM

Here's the code that looks for the file based on the field:

<tr>
<td>
<?php
$category_query = tep_db_query("select cd.categories_name from " .
TABLE_CATEGORIES_DESCRIPTION . " cd where cd.categories_id = '" .
(int)$current_category_id . "' and cd.language_id = '" .
(int)$languages_id . "'");
$category = tep_db_fetch_array($category_query);
$filename =
'includes/descriptions/'.$category['categories_name'].'.php';
if (file_exists($filename)) { include( $filename );
} ?>
<?php include(DIR_WS_MODULES . FILENAME_PRODUCT_LISTING);
?>
</td>
</tr>

Here's my thoughts:

Yes... and description is inserted here:
$category['categories_name']

so it looks for a file names, for exaple

3" Wide Boxes and it can't find it because I wasn't able to save a file called 3" Wide Boxes... if there was a way to substitute an accepted character (or omit it) whenever it runs into an unaccepted character that would work.

So when it gets a description of:

3" Wide Boxes it would look for 3 Wide Boxes

That *would* work.

I know I'm on the right path...

GottaDiesel 04-17-2006 03:11 PM

Here's what I was told on another forum...

Dang if I know what it means:


look into str_replace() or use a regular expression function (preg_replace()) to convert multiple "bad" characters to "good" characters (or omit them)

MikeTangas 04-17-2006 05:24 PM

Rename your file to "3 inch wide boxes" so you don't have to mess aorund trying to get the system to recognize the ' " ' symbol.

GottaDiesel 04-17-2006 05:32 PM

Learned about this cool command today:

rawurlencode()

So I did:

'includes/descriptions/'.rawurlencode($category['categories_name']).'.php';

and now my file names have to look like this:

3%22Inch%20Box.php

BUT... guess what... IT WORKS PERFECTLY!!!!!!

:) :) :)

Pete


All times are GMT -4. The time now is 01:35 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2026, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0
Copyright 2024 Pelican Parts, LLC - Posts may be archived for display on the Peach Parts or Pelican Parts Website