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
pilau
Forum Regular
Posts: 594 Joined: Sat Jul 09, 2005 10:22 am
Location: Israel
Post
by pilau » Fri Sep 30, 2005 1:17 am
How should I replace a single quote, with the HTML entity '?
ruchit
Forum Commoner
Posts: 53 Joined: Mon Sep 26, 2005 6:03 am
Post
by ruchit » Fri Sep 30, 2005 1:25 am
Code: Select all
str_replace("'", "#39;", $subject);
PS: If you're looking at this for backslshing problem, then use
pilau
Forum Regular
Posts: 594 Joined: Sat Jul 09, 2005 10:22 am
Location: Israel
Post
by pilau » Fri Sep 30, 2005 3:10 am
Thanks-a-lot, that solved my problem!
Jenk
DevNet Master
Posts: 3587 Joined: Mon Sep 19, 2005 6:24 am
Location: London
Post
by Jenk » Fri Sep 30, 2005 3:18 am
ruchit wrote:
PS: If you're looking at this for backslshing problem, then use
This is incorrect, well, syntactically it is correct, but it is inappropraite for this use.
That would remove all backslashes, not just the ones inputted by magic_quotes.
Use stripslashes to remove the escaping back slashes.
ruchit
Forum Commoner
Posts: 53 Joined: Mon Sep 26, 2005 6:03 am
Post
by ruchit » Fri Sep 30, 2005 3:23 am
i am so wrong... but jenk did u read the other thread?? ... and if you didn't... pilau only asked for str_replace function on this thread.
Jenk
DevNet Master
Posts: 3587 Joined: Mon Sep 19, 2005 6:24 am
Location: London
Post
by Jenk » Fri Sep 30, 2005 3:29 am
I'v also just noticed it is syntactically incorrect aswell
it should be
Code: Select all
<?php
$string = str_replace ("\\", "", $string);
?>
But the problem with using the above, is what happens when a user wants to post a backslash?
For example, the below input
FAO: Bob - You can find the shared directory at: \\server\folder
Skara
Forum Regular
Posts: 703 Joined: Sat Mar 12, 2005 7:13 pm
Location: US
Post
by Skara » Fri Sep 30, 2005 1:21 pm
If a user inputs the following:
"Doug's horse jumped the fence," said \\stable\pen.
would translate to this:
\"Doug\'s horse jumped the fence,\" said \\\\stable\\pen.
Jenk
DevNet Master
Posts: 3587 Joined: Mon Sep 19, 2005 6:24 am
Location: London
Post
by Jenk » Fri Sep 30, 2005 4:34 pm
That's with magic quotes on, but if you used str_replace to remove the slashes, there would be none at all.