Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace Single Quote (apostrophe)

Status
Not open for further replies.

DonP

IS-IT--Management
Jul 20, 2000
684
US
This has me pulling my hair out as I don't see anything wrong. It is working for the other characters/spaces except that the apostrophe is not being replaced:

Code:
$Characters = array("  ", chr(39), "'", " ");
$StringReplace = array(" ", "", "", "_");
$DocName = str_replace($Characters, $StringReplace, $DocName);

I tried the str_replace() function both as individual lines and as the array above, I tried escaping the character and I tried the chr(39) code. Does someone have better eyes to see why it won't work? There are no error messages yet the apostrophe remains.

Don
Experienced in HTML, Perl, PHP, VBScript, PWS, IIS and Apache and MS-Access, MS-SQL, MySQL databases
 
try this:
Code:
$Characters = array("  ", chr(39), "'", " "[red],chr(146)[/red]);
$StringReplace = array(" ", "", "", "_"[red],""[/red]);
$DocName = str_replace($Characters, $StringReplace, $DocName);
 
Good suggection but actually I had thought of that. As the apostrophe is in a file name, which I failed to mention, it seemed unlikely if not impossible for it to be a Word character. Unfortunately that theory seems correct as it is not a Word apostrophe.

What's happening is that it is not replacing the apostrophe but rather the name is being cut off and is only showing the part after it. Saying that, I just realized that the problem is likely a more basic one and is probably being cut before it even gets to this code. Any thoughts? Otherwise thanks for the suggestion.

Don
Experienced in HTML, Perl, PHP, VBScript, PWS, IIS and Apache and MS-Access, MS-SQL, MySQL databases
 
do some debugging on the shape/contents of the variables before and after you parse them. i think your assumption sounds right though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top