Dear Martin, it worked!! Thank you SO much! - Shawna

-----Original Message-----
From: Martin Towell
To: '[EMAIL PROTECTED]'; [EMAIL PROTECTED]
Sent: 1/20/02 10:25 PM
Subject: RE: [PHP] agh - what am I doing wrong - regular expressions

try this... 
I changed 
  1. the double quotes in "$pattern = ..." to single quotes 
  2. escaped the "?" 
  3. used ereg_replace to do everything, dropping the while loop 

------------------------ 
$content = " http://www.globalhealth.org/text.php3?id=151
<http://www.globalhealth.org/text.php3?id=151>  
adjfladjfajdfkladfjl;kadjf 
jlkadjflkajdflkj jadklfjalkdjfl;df jalkdfj;ldafj"; 

$pattern = ' http://( <http://(> [\/~_\.0-9A-Za-z#&=-\?]+)'; 

$content = ereg_replace($pattern, "<A
HREF=\"javascript:externalURL('\\1');\">\\1</A>", $content); 

print $content; 
------------------------ 

-----Original Message----- 
From: [EMAIL PROTECTED] [ mailto:[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]> ] 
Sent: Monday, January 21, 2002 2:46 AM 
To: [EMAIL PROTECTED] 
Subject: [PHP] agh - what am I doing wrong - regular expressions 


Good morning everyone, 

I'm trying to adapt existing php code that uses a while loop to scan
content 
for a url pattern, take the matches and add link tags (<a>) around them
so 
the url with be made into "hot links. Simple enough right? Nevertheless,
I 
seem to be having trouble with urls that have question marks in them. 

Here is the existing code that works - except with question marks: 

******************** 

$content = " http://www.globalhealth.org/text.php3?id=151
<http://www.globalhealth.org/text.php3?id=151>  
adjfladjfajdfkladfjl;kadjf 
jlkadjflkajdflkj jadklfjalkdjfl;df jalkdfj;ldafj"; 

$pattern = " http://( <http://(> [\/~_\.0-9A-Za-z#&=-]+)"; 

while(ereg($pattern, $content, $match)){ 
        $http_old = $match[0];  
        $http = "dubdubdub" . $match[1] . $match[2]; 
        $url = "<A HREF=\"javascript:externalURL('$http')\";>$http</A>";

        $content = ereg_replace($http_old, $url, $content);     
        }; 

$content = ereg_replace("dubdubdub", " http:// <http://> ", $content); 

print $content; 

****************** 

Here's the same code with the question mark in the pattern variable.
When I 
add the question mark and test the page, my browsers just "hang".
Escaping 
the question mark doesn't seem to help (and I also read that escapes
aren't 
necessary between square brackets]: 

$content = " http://www.globalhealth.org/text.php3?id=151
<http://www.globalhealth.org/text.php3?id=151>  
adjfladjfajdfkladfjl;kadjf 
jlkadjflkajdflkj jadklfjalkdjfl;df jalkdfj;ldafj"; 

$pattern = " http://( <http://(> [\/~_\.0-9A-Za-z#&=?-]+)"; 

while(ereg($pattern, $content, $match)){ 
        $http_old = $match[0];  
        $http = "dubdubdub" . $match[1] . $match[2]; 
        $url = "<A HREF=\"javascript:externalURL('$http')\";>$http</A>";

        $content = ereg_replace($http_old, $url, $content);     
        }; 

$content = ereg_replace("dubdubdub", " http:// <http://> ", $content); 

print $content; 


************************* 

In an attempt to find the problem, I did a test with the following code
and 
received the result I want - which leads me to believe the problem is 
possibly with the while loop or the ereg_replace?? 

$content = " http://www.globalhealth.org/text.php3?id=151
<http://www.globalhealth.org/text.php3?id=151>  
adjfladjfajdfkladfjl;kadjf 
jlkadjflkajdflkj jadklfjalkdjfl;df jalkdfj;ldafj"; 

$pattern = " http://( <http://(> [/~_.0-9A-Za-z#&=?-]+)"; 

ereg($pattern, $content, $match); 

print "<A HREF=\"javascript:externalURL('$match[0]')\";>$match[0]</A>"; 

****************** 

I'm completely confused. I have a feeling there is any easy answer and
if I 
wasn't so frustrated I'd be embarrassed to say that I've spent hours on 
this... 

Thanks in advance for your help, Shawna 

-- 
PHP General Mailing List ( http://www.php.net/ <http://www.php.net/> ) 
To unsubscribe, e-mail: [EMAIL PROTECTED] 
For additional commands, e-mail: [EMAIL PROTECTED] 
To contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to