Page 1 of 2
[SOLVED] how to replace \" with just "
Posted: Wed Apr 06, 2011 12:26 am
by stevestark5000
i got a strange problem. when i preview my code the left, center, right div had "\" in them eg <div align=\"center\">. i need to rid the "\" in them. the following code had "\" in them. i would like to get rid of the "\" in them. i would like to search for \" and replace with ".
the $content is displayed from a preview of post. in the $content i have the full code as below. i would like to replace all word of \" with " in it. i need an experience programmer to help me with them. thank you.
Code: Select all
<div align=\"right\">Right Justified Text</div><div align=\"center\">Centered Text</div>
Re: how to replace \" with just "
Posted: Wed Apr 06, 2011 12:49 am
by califdon
I don't understand your question. If this is a script, why don't you simply remove the backslashes in the editor? If you are processing this from some other source, describe where it is coming from.
Re: how to replace \" with just "
Posted: Wed Apr 06, 2011 8:42 pm
by stevestark5000
it is coming from a forum post. the preview button. the preview places \" in the code. i need to remove them by some php code. if a person typed in "hello world\" and right aligned it, then the right align would not work because of the \ in them. in this case, i need to rid \ but not in hello world\. this is why i need to search for \" and not just search for \
Re: how to replace \" with just "
Posted: Wed Apr 06, 2011 8:45 pm
by fugix
so this <div> that you show above is user generated?
Re: how to replace \" with just "
Posted: Wed Apr 06, 2011 8:55 pm
by califdon
But how are you getting this? Are you receiving this in a POST variable from a form? Are you scraping this from another forum? There are a lot of issues here, and you're not explaining where this data comes from well enough for me to offer any solution to you. Are you familiar with regular expressions, specifically the PHP function preg_replace() (
http://php.net/manual/en/function.preg-replace.php)?
Re: how to replace \" with just "
Posted: Wed Apr 06, 2011 9:12 pm
by stevestark5000
i getting this from a POST variable from a form. the div is not user generated. it from a forum button right align. the content if a forum preview from the preview button. why does it matter where the code came from. the code is "<div \"" from the $content. now how to rid the \" from $content? the preg_replace() is what i need but i am not sure how to use it. can i have an example in my case?
Re: how to replace \" with just "
Posted: Wed Apr 06, 2011 9:32 pm
by fugix
or even strip_slashes()
Re: how to replace \" with just "
Posted: Wed Apr 06, 2011 9:38 pm
by fugix
Code: Select all
preg_replace('\', '', $_POST['']);
Re: how to replace \" with just "
Posted: Wed Apr 06, 2011 10:05 pm
by stevestark5000
fugix wrote:Code: Select all
preg_replace('\', '', $_POST['']);
the above quote will remove all \ and even the ones the user posts. i needed to search for \" and replace with " will this work? notice the quotes in code below
Code: Select all
preg_replace('\"', '"', $_POST[''])
Re: how to replace \" with just "
Posted: Wed Apr 06, 2011 10:17 pm
by fugix
yes
Re: how to replace \" with just "
Posted: Wed Apr 06, 2011 10:22 pm
by stevestark5000
thank you
Re: how to replace \" with just "
Posted: Wed Apr 06, 2011 10:25 pm
by fugix
no problem
Re: how to replace \" with just "
Posted: Thu Apr 07, 2011 1:17 am
by stevestark5000
i am getting an error with the code. are you sure the double quotes is ok?
Code: Select all
preg_replace('\"', '"', $_POST[''])
Re: how to replace \" with just "
Posted: Thu Apr 07, 2011 10:39 am
by fugix
maybe not..might be trying to just escape the double quotes..which would render preg_replace() useless
Re: how to replace \" with just "
Posted: Thu Apr 07, 2011 10:40 am
by fugix
can you post the error please?