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

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
capesystem
Forum Newbie
Posts: 1
Joined: Wed Jul 22, 2009 10:10 am

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

Post 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);
}
?>
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

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

Post by Mark Baker »

Look to the stripslashes() function and make sure you know the setting for magic quotes
UnknownOne
Forum Newbie
Posts: 5
Joined: Thu Jul 23, 2009 8:52 am

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

Post 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. =)
User avatar
Chalks
Forum Contributor
Posts: 447
Joined: Thu Jul 12, 2007 7:55 am
Location: Indiana

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

Post 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().
Post Reply