Re: PHP function inside a regex - possible?

From: Date: Thu, 01 Jun 2000 18:47:40 +0000
Subject: Re: PHP function inside a regex - possible?
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-866@lists.php.net to get a copy of this message
At 07:14 PM 6/1/00 +0000, kev wrote:
Thanks Zak, unfortunately the /g modifier doesn't appear to be supported and with the U modifier I get nothing where term2 should be bolded. I have sent a file with some 'real-life' sample text to Andrea, he is going to look at it, his last suggestion worked for him but not for me, he's using a PHP4 snapshot from late March and using PHP4B3. I'm going to build a PHP4RC1 binary now...
Hi Kev, I did a little test and encountered the same problem with g.. oh well. However, the s modifier should also do the trick. Here is a test that I did: <SCRIPT LANGUAGE="PHP"> print $text = ' <b>Test 1</b> Test 1<BR> <b>Test 2</b> Test 2<BR> <b>Test 3 </b> Test 3<BR> <b>Test 4</b> Test 4<BR><BR> '; print preg_replace ("/<b>(.+)<\/b>/ieUs", "'<b><a href=search.php?query='.urlencode (trim ('\\1')).'>\\1</a></b>'", $text); </SCRIPT> It works with no complaints on php 4.0.0 Also, note the use of trim to stop pesky whitespace from being included in your search terms. Good Luck! Zak

« previous php.general (#866) next »