Results 1 to 3 of 3
Thread: php Regex help
-
04-05-2011, 04:17 PM #1Junior Guru Wannabe
- 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
-
04-05-2011, 04:59 PM #2Web Hosting Guru
- 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>
-
04-05-2011, 05:29 PM #3Junior Guru Wannabe
- 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
-
(paid work) PHP regex guru is needed for very complicated regex requirement
By mrzippy in forum Employment / Job OffersReplies: 2Last Post: 03-30-2006, 05:10 PM -
php regex help
By portalplanet in forum Programming DiscussionReplies: 3Last Post: 04-19-2005, 10:14 AM -
PHP regex question
By JPortal in forum Programming DiscussionReplies: 3Last Post: 10-27-2003, 12:22 AM -
php... regex.. >:o
By Joshua44 in forum Programming DiscussionReplies: 0Last Post: 05-11-2003, 06:51 PM -
PHP regex help please!
By chilliboy in forum Web Hosting LoungeReplies: 0Last Post: 12-02-2000, 10:41 AM