Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
05-01-2006, 11:18 PM #1
- Join Date
- Apr 2006
- Thanked 0 Times in 0 Posts
Using PHP tags in arguements, and variables
I'm getting some odd results when using <?php or ?> in a script.
What I am doing is parsing a PHP/HTML file, and passing the segments to a form via a hidden input. I don't want to execute the code, just pass it on for inclusion in a file.
My question is this: Can I use the PHP open and or close tags in function arguements, or variables, without breaking the code? My guess was no, but the parsing "seems" to work, but when it goes to the form I get odd stuff. So I'm wondering if I'm just plain trying to do a no-no here.
Example (breaks file into PHP and HTML pieces, then passes pieces to a form for editing, recombining and saving):
preg_match_all("|(<\?php.*\?>)(.*)(<\?php.*\?>)|s", $contents, $matches);
$head = nl2br(htmlentities($matches));
//thus $head is something like <?php some stuff ?>
<input type="hidden" name="head" value="$head" />
So is using raw PHP open/close tags in an argument, or passing passing them in a variable not possible/good practice?
05-02-2006, 11:20 AM #2
- Join Date
- Dec 2004
- the U.S. of freakin' A.
- Thanked 155 Times in 146 Posts
you could bypass this potential problem by just making your variable (that contains the string representation of your code) a global variable...then you don;t need to pass it into your function via the argument...
Doing it this way, as long as the PHP code is inside a variable string, you should be fine...
Passing the data into the fumction via the argument is the prefered method, but if it doesn;t work, you could try doing what i said here...
Last edited by chump2877; 05-02-2006 at 11:25 AM.
Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
[Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
Get free updates about new software version releases, features, and bug fixes!
05-02-2006, 05:34 PM #3
I think you're getting odd stuff because your regular expression is wrong. Shouldn't some or all of those matches be lazy so they don't swallow up the whole document? Try:
$matches will contain full php blocks and $matches will just have the contents, minus the delimiting tags.PHP Code:
preg_match_all('/<\?php(.*?)\?>/i', $phpstring, $matches);