[SOLVED] how to replace \" with just "

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

stevestark5000
Forum Commoner
Posts: 61
Joined: Thu Jan 27, 2011 12:08 am

[SOLVED] how to replace \" with just "

Post 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>
Last edited by stevestark5000 on Thu Apr 07, 2011 8:38 pm, edited 2 times in total.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: how to replace \" with just "

Post 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.
stevestark5000
Forum Commoner
Posts: 61
Joined: Thu Jan 27, 2011 12:08 am

Re: how to replace \" with just "

Post 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 \
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

Re: how to replace \" with just "

Post by fugix »

so this <div> that you show above is user generated?
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: how to replace \" with just "

Post 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)?
stevestark5000
Forum Commoner
Posts: 61
Joined: Thu Jan 27, 2011 12:08 am

Re: how to replace \" with just "

Post 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?
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

Re: how to replace \" with just "

Post by fugix »

or even strip_slashes()
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

Re: how to replace \" with just "

Post by fugix »

Code: Select all

preg_replace('\', '', $_POST['']);
stevestark5000
Forum Commoner
Posts: 61
Joined: Thu Jan 27, 2011 12:08 am

Re: how to replace \" with just "

Post 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[''])
Last edited by stevestark5000 on Wed Apr 06, 2011 10:21 pm, edited 1 time in total.
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

Re: how to replace \" with just "

Post by fugix »

yes
stevestark5000
Forum Commoner
Posts: 61
Joined: Thu Jan 27, 2011 12:08 am

Re: how to replace \" with just "

Post by stevestark5000 »

thank you
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

Re: how to replace \" with just "

Post by fugix »

no problem
stevestark5000
Forum Commoner
Posts: 61
Joined: Thu Jan 27, 2011 12:08 am

Re: how to replace \" with just "

Post by stevestark5000 »

i am getting an error with the code. are you sure the double quotes is ok?

Code: Select all

preg_replace('\"', '"', $_POST[''])
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

Re: how to replace \" with just "

Post by fugix »

maybe not..might be trying to just escape the double quotes..which would render preg_replace() useless
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

Re: how to replace \" with just "

Post by fugix »

can you post the error please?
Post Reply