zbrahead Posted November 4, 2006 Share Posted November 4, 2006 For example:[code]$randomvariable = "<?php header("location:Http:somesite.com");exit;?>"echo($randomvariable); #failsprint($randomvariable); #fails[/code]how do i get the string contents parsed?!?!?! Quote Link to comment https://forums.phpfreaks.com/topic/26142-i-have-a-variable-how-do-i-parse-its-contents/ Share on other sites More sharing options...
LazyJones Posted November 4, 2006 Share Posted November 4, 2006 You can't execute PHP code that way (if that's what you are after).For pulling something out of a string (maybe the url, in this case?), there's lots of useful functions for example preg_match() and strstr() Good question is, why would you have something like that in a variable... Quote Link to comment https://forums.phpfreaks.com/topic/26142-i-have-a-variable-how-do-i-parse-its-contents/#findComment-119560 Share on other sites More sharing options...
zbrahead Posted November 4, 2006 Author Share Posted November 4, 2006 it would've been extracted from mysql Quote Link to comment https://forums.phpfreaks.com/topic/26142-i-have-a-variable-how-do-i-parse-its-contents/#findComment-119607 Share on other sites More sharing options...
wildteen88 Posted November 4, 2006 Share Posted November 4, 2006 If that is the code in your mysql database then you'll want use eval in order run the PHP code that is stored in your database.for example when you get it out of your database you'll want to do something like this:[code=php:0]eval("$your_var = \"$row['column_name_here']\";");[/code] Quote Link to comment https://forums.phpfreaks.com/topic/26142-i-have-a-variable-how-do-i-parse-its-contents/#findComment-119628 Share on other sites More sharing options...
Barand Posted November 4, 2006 Share Posted November 4, 2006 Either enclose the string in single quotes or escape the inner double quotes, then echo it using htmlentities()[code]<?php$randomvariable = '<?php header("location:Http:somesite.com");exit;?>';echo htmlentities($randomvariable);?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/26142-i-have-a-variable-how-do-i-parse-its-contents/#findComment-119649 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.