How to remove apostrophes in PHP
I am having a database created in PHP. Many of the tables in it contains apostrophes. I want to remove that slashes in my result and here lies my problem.
Example: for "I am under the tree."
I get the result: "I'm in l \"
I tried the addslashes but it changes nothing.
PHP Code:
<input type='text' name='description4' size='100' value='".addslashes($
data['description4_information'])."' />
Re: How to remove apostrophes in PHP
Quote:
Originally Posted by
Sean J
I tried the addslashes but it changes nothing.
PHP Code:
<input type='text' name='description4' size='100' value='".addslashes($
data['description4_information'])."' />
Here lies your actual problem. Basically addslashes adds slashes whereas stripslashes removes slashes. So, in short, use stripslashes rather than addslashes.
Re: How to remove apostrophes in PHP
You put this:
value="<?php echo $data['description4_information']"' />
or begin with a echo '... value = ".addslashes ($data[' description4_information'])."' /> ', do this:
echo "<input type='text' name='description4' size='100' value=".$data['description4_information'])." />";
Re: How to remove apostrophes in PHP
Quote:
Originally Posted by
Sean J
PHP Code:
<input type='text' name='description4' size='100' value='".addslashes($
data['description4_information'])."' />
This is happening because you are using When the compiler encounters an apostrophe, it assumes that this is the end of the statement. In short your text get escapes with htmlspecialchars () like apostrophe, slashes, etc. If you don't want to give it any value then better don't use it.