Page 1 of 1

string help

Posted: Tue May 14, 2002 7:50 am
by moehome
hey ya,
I have some text that contains " and ' symbols,
since I'd like to process these files as strings, I need to add a \ before with addslashes, but when I try to do so, I need to define the string, which doesn't work, since parts of the text are ignored or I get some parse-errors

you know how to solve that problem??

Strip em

Posted: Tue May 14, 2002 7:59 am
by pHaZed
Hey,
Since u add the slashes, U can reverse it juz before u want to use the string.

Code: Select all

stripslashes();

Posted: Tue May 14, 2002 8:06 am
by moehome
but I can't even add the bloody slashes since, just get an error or not the whole text
eg.: how to process "I ate at my mother's"????
will get a f**king parse error

greez moe

Posted: Tue May 14, 2002 8:20 am
by mikeq
Are you trying to add the ''s automatically or are you just going through the text adding them by hand?

Posted: Tue May 14, 2002 8:23 am
by pHaZed
Well,
I played around a little and come to the conclusion after reading the documentation
that it would seem to be easyier to just add the slashes around the symbols in the string...
and then strip them

Code: Select all

<?PHP
$string= "I had dinner at'her mumas' house it was "quite"";
$stripped= stripslashes($string);
echo "$string";
?>

Posted: Tue May 14, 2002 10:07 am
by moehome
ey man, I NEED TO ADD THOSE SLASHES, not remove them!!
greez moe

Posted: Wed May 15, 2002 2:48 am
by twigletmac
moehome wrote:"I ate at my mother's"- will get a parse error
You won't get a parse error on this because the string is in double quotes and that single quote will be ignored. This:

Code: Select all

echo 'I ate at my mother's';
would get a parse error as PHP would consider that the string ended after the r of mother.

Where are you getting the data from? If it's coming from a form slashes are automagically added where needed. If it's coming from a flat file or a database you could addslashes as you read the data out of it. If you're typing the strings in by hand you might as well add the slashes as you do it, AFAIK there's really no way around that except by maybe adding two single quotes ('') and then using str_replace to change those to escaped double quotes (").

Everybody's only trying to help.

Mac

Posted: Wed May 15, 2002 7:44 am
by moehome
thx a lot,
I tried it with direct written text, which didn't work, with fopen it is ain't no prob.!
:D :D :D :mrgreen: