Jump to content

[SOLVED] evaluating an escaped string


RussellReal

Recommended Posts

lets say I have this string '\n\t\r\n\n\x3C' is there a function which CAN properly handle each special escape char's special meaning..

 

I don't know how to explain it, I just hope someone can understand what I am trying to say..

 

I tried strip slashes

but that just turns:\n\t\r\n\n\x3C

into: ntrnnx3C

 

and I want it to turn it into the special meanings

Link to comment
https://forums.phpfreaks.com/topic/137498-solved-evaluating-an-escaped-string/
Share on other sites

I know the difference between single and double quotes.. if I deliberately set my variable with single quotes.. and then I want to make it evaluate at a later time in the script.. how would I go about doing that?

okay.. lets give an example

 

I have a text file called

 

blah.txt

 

which contains

 

\x3cb\x3eOMG NO FREAKING WAY\x3c/b\x3e

 

now when I do

$e = file_get_contents("blah.txt");

 

$e will contain the contents, EXACTLY as it was in the text file.. I want the hex to evaluate, I want to know if there is a function to do so.

 

Thank you very much foir your replies so far guys

'\n\t\r\n\n\x3C'

 

That is what bothers me. If you are inputting that with the single quotes, of course that is taken literally.

 

Use double quotes

"\n\t\r\n\n\x3C"

 

And those characters will be put into their special meaning.

lol... I KNOW what  the difference in QUOTES are.. nevermind forget I asked.. lol

 

Sorry about that, it is hard to know how much you know, especially since you are relatively new.

 

Do you know how the text is being entered into the text file? Like is html_entities is being used or if it is being entered using utf8_encode ?

 

Not sure of either of those would help you out or not....

Yeah, I really don't think theres a file, I'd have to pull something like eval("\$var = \"{$actualVar}\";");

 

to evaluate the \n \r you know the escaped characters, I just set up a str replace

 

$image[] = str_replace(array('\x3c','\x3e','\x3d','\x26'),array('<','>','=','&'),substr($data,$q1 + 1,$start - ($q1 + 1)));

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.