how to remove \ in php string display

Coding Critique is the place to post source code for peer review by other members of DevNetwork. Any kind of code can be posted. Code posted does not have to be limited to PHP. All members are invited to contribute constructive criticism with the goal of improving the code. Posted code should include some background information about it and what areas you specifically would like help with.

Popular code excerpts may be moved to "Code Snippets" by the moderators.

Moderator: General Moderators

Post Reply
waseem83
Forum Commoner
Posts: 54
Joined: Tue Jun 23, 2009 3:51 am
Contact:

how to remove \ in php string display

Post by waseem83 »

My code is

$message="We're looking at developing our website.";

$body= "My message is,\n\n\n\n\t\t\t".$message";

echo $body;

I get result

We\'re looking at developing our website.

Can any body tell me how to remove \ from the printed string?

Thanks in advance
pbs
Forum Contributor
Posts: 230
Joined: Fri Nov 07, 2008 5:31 am
Location: Nashik, India
Contact:

Re: how to remove \ in php string display

Post by pbs »

Use

Code: Select all

 
<?php
    stripslashes($str);
?>
 
MichaelR
Forum Contributor
Posts: 148
Joined: Sat Jan 03, 2009 3:27 pm

Re: how to remove \ in php string display

Post by MichaelR »

Alternatively, if you have access to the config.ini file, turn magic_quotes_gpc to off, and remember to escape strings with mysql_real_escape_string() when you are performing an SQL query.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: how to remove \ in php string display

Post by jackpf »

Oooooor, if you don't have access to your php.ini, you can turn off magic quotes in a htaccess file with a php_flag.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Re: how to remove \ in php string display

Post by Jenk »

Aaaaaaaaand you can post in the correct section. Coding Critique is not for general coding questions, help with errors, etc.
Post Reply