Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Apr 2006
    Posts
    2
    Thanks
    0
    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[1][0]));
    //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?

    Thanks.

  • #2
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,859
    Thanks
    22
    Thanked 157 Times in 148 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 12:25 PM.
    Regards, R.J.

    ---------------------------------------------------------

    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!
    ♪♪ …Need Web Hosting For My YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪

  • #3
    Regular Coder ralph l mayo's Avatar
    Join Date
    Nov 2005
    Posts
    951
    Thanks
    1
    Thanked 31 Times in 29 Posts
    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:

    PHP Code:
    preg_match_all('/<\?php(.*?)\?>/i'$phpstring$matches); 
    $matches[0] will contain full php blocks and $matches[1] will just have the contents, minus the delimiting tags.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •