PHP

Moderators: None (Apply to moderate this forum)
Number of threads: 1848
Number of posts: 5016

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Removing \' from strings Posted by novabond on 1 Jun 2003 at 2:08 PM
Hey, I'm getting input from a form in html, and then writing that information to a file. Now, when a ' (and i suppose a " as well) is typed in... into the file \' appears. I understand why it is doing this... but is there a way so it DOESN'T do that.. I am sure there's some function that removes it or something but I don't know what it is. I just iddn't want to have to loop through the whole file and remove occurences of \' and things like that. Any help is appreciated.
I'm hoping there's a function that can remove it from the string so i can do:

1)Get text from input box
2)remove the \' and stuff
3)write to file

thanks
Report
Re: Removing \' from strings Posted by awulf on 1 Jun 2003 at 11:51 PM
sure, you can use the str_replace function. here's an example

$my_str = "hello. isn\\\'t it annoying to see \\\' in my file?!";
// now my string literally is:
// "hello. isn\'t it annoying to see \' in my file"
//
// i assume you'd like to turn a \' into just a '
//
// you can do this with one call to str_replace

$my_str = str_replace("\\\'", "\'", $my_str);

// or if you want to take out the \' altogether, use
// this line instead

$my_str = str_replace("\\\'", "", $my_str);

hope this helps,
--------
awulf :.
--------
bus: http://www.inversiondesigns.com
me : http://awulf.inversiondesigns.com

Report
Re: Removing \' from strings Posted by emperor on 3 Jun 2003 at 7:50 AM
: Hey, I'm getting input from a form in html, and then writing that information to a file. Now, when a ' (and i suppose a " as well) is typed in... into the file \' appears. I understand why it is doing this... but is there a way so it DOESN'T do that.. I am sure there's some function that removes it or something but I don't know what it is. I just iddn't want to have to loop through the whole file and remove occurences of \' and things like that. Any help is appreciated.
: I'm hoping there's a function that can remove it from the string so i can do:
:
: 1)Get text from input box
: 2)remove the \' and stuff
: 3)write to file
:
: thanks
:

couldn't you just use stripslashes ()?

Report
Re: Removing \' from strings Posted by novabond on 3 Jun 2003 at 7:27 PM
: Hey, I'm getting input from a form in html, and then writing that information to a file. Now, when a ' (and i suppose a " as well) is typed in... into the file \' appears. I understand why it is doing this... but is there a way so it DOESN'T do that.. I am sure there's some function that removes it or something but I don't know what it is. I just iddn't want to have to loop through the whole file and remove occurences of \' and things like that. Any help is appreciated.
: I'm hoping there's a function that can remove it from the string so i can do:
:
: 1)Get text from input box
: 2)remove the \' and stuff
: 3)write to file
:
: thanks
:


both of you are correct. Damn thanks a lot




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.