Results 1 to 3 of 3

Thread: php Regex help

  1. #1
    Join Date
    Jun 2007
    Posts
    57

    php Regex help

    Hi All.

    I am having problems with what seems to be a straightforward regex and will appreciate a few eyes on the issue and tips where I have screwed up.

    Basically, I am trying to add to the head section of a html page.

    The html has already been successfully loaded in $htmlData and the additional data to be added is in $extraHeadData.

    Can anyone kindly point me to why the regex below fails to match?

    $htmlFinal = preg_replace('#<\/head>#i', $extraHeadData . "\n</head>", $htmlData);

    Thanks

  2. #2
    Join Date
    Apr 2008
    Posts
    334
    Curiously, it seems to work fine :

    PHP Code:
    <?php

    ini_set
    ('display_errors''1');
    error_reporting(E_ALL);

    $htmlData '<head>test</head>';
    $extraHeadData 'extra';
    $htmlFinal preg_replace('#<\/head>#i'$extraHeadData "\n</head>"$htmlData);

    echo 
    $htmlFinal// <head>testextra\n</head>

  3. #3
    Join Date
    Jun 2007
    Posts
    57
    This does indeed. Error was elsewhere.

    I was doing the equivalent of ...

    PHP Code:
    $htmlData '<head>test</head>'
    $extraHeadData 'extra'
    $htmlFinal preg_replace('#<\/head>#i'$extraHeadData "\n</head>"$htmlData); 
    echo 
    $htmlData// instead of $htmlFinal 

Similar Threads

  1. Replies: 2
    Last Post: 03-30-2006, 05:10 PM
  2. php regex help
    By portalplanet in forum Programming Discussion
    Replies: 3
    Last Post: 04-19-2005, 10:14 AM
  3. PHP regex question
    By JPortal in forum Programming Discussion
    Replies: 3
    Last Post: 10-27-2003, 12:22 AM
  4. php... regex.. >:o
    By Joshua44 in forum Programming Discussion
    Replies: 0
    Last Post: 05-11-2003, 06:51 PM
  5. PHP regex help please!
    By chilliboy in forum Web Hosting Lounge
    Replies: 0
    Last Post: 12-02-2000, 10:41 AM

Posting Permissions

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