string help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
moehome
Forum Newbie
Posts: 6
Joined: Mon May 13, 2002 10:57 am

string help

Post 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??
User avatar
pHaZed
Forum Commoner
Posts: 28
Joined: Wed May 01, 2002 2:44 am
Location: Sydney -AU

Strip em

Post by pHaZed »

Hey,
Since u add the slashes, U can reverse it juz before u want to use the string.

Code: Select all

stripslashes();
moehome
Forum Newbie
Posts: 6
Joined: Mon May 13, 2002 10:57 am

Post 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
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post by mikeq »

Are you trying to add the ''s automatically or are you just going through the text adding them by hand?
User avatar
pHaZed
Forum Commoner
Posts: 28
Joined: Wed May 01, 2002 2:44 am
Location: Sydney -AU

Post 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";
?>
moehome
Forum Newbie
Posts: 6
Joined: Mon May 13, 2002 10:57 am

Post by moehome »

ey man, I NEED TO ADD THOSE SLASHES, not remove them!!
greez moe
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
moehome
Forum Newbie
Posts: 6
Joined: Mon May 13, 2002 10:57 am

Post 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:
Post Reply