Page 1 of 1

A php function for removing "\" from a sentence ??

Posted: Thu Jul 23, 2009 4:55 am
by capesystem
Hi,

I hope someones come across this problem. The problem is everytime php see's a apostophe (their's) it automatically adds a backslash to it. I was hoping if anyone had a function to remove all the backslashes from a given sentance.

I have written a little snippet of code and was hoping if someone could have a look and see where i'm going wrong.
THANKS.
<ALL HELP APPRECIATED>

Here's my code below:

<?php
//Remove all backslash

$address="hello worl'd";
$n = strlen($address);

for($i=0; $i<$n; $i++)

If substr("$address","$i","$i", <> "\") //then
{
substr($address);
}
?>

Re: A php function for removing "\" from a sentence ??

Posted: Thu Jul 23, 2009 6:31 am
by Mark Baker
Look to the stripslashes() function and make sure you know the setting for magic quotes

Re: A php function for removing "\" from a sentence ??

Posted: Thu Jul 23, 2009 9:03 am
by UnknownOne
Could we not use the str_replace() function here?

I've only just started off and not sure how exactly to get the str_replace function working but I should do with a little research.

Something like:

Code: Select all

str_replace("/", "", "the location?");
 //First quote should identify what should be replaced
//second quote should identify what it should be replaced by
//Third and final quote should identify the location of the string?
I'm not exactly sure as I'm not too clear on it myself.
Anyone care to help out capesystem and myself?

Thanks in advance for any responses. =)

Re: A php function for removing "\" from a sentence ??

Posted: Thu Jul 23, 2009 9:58 am
by Chalks
you could, but I'm sure your issue is (as Mark pointed out) with magic_quotes_gpc and not using stripslashes(). Turn off magic quotes and use stripslashes().