GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 31-May-2003, 04:41
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough

Issue with preg_replace, e modifier inside PHP classes


Recently, I had an issue with using preg_replace() with the e modifier inside a class. For example, if you were to save the sample code below to a file named test.php and view it, it doesn't work the way it used to (I am on PHP ver 4.3.1).

FILENAME: TEST.PHP
PHP Code:

<?php
$str = 'The quick brown fox [b][[/b]B]jumped[/b] over the lazy dogs.
        The quick brown fox [b][[/b]B]jumped[/b] over the lazy dogs.
        The quick brown fox [b][[/b]B]jumped[/b] over the lazy dogs.
        The quick brown fox [b][[/b]B]jumped[/b] over the lazy dogs.
        The quick brown fox [b][[/b]B]jumped[/b] over the lazy dogs.';

$t = new Test();
$str = $t->ProcessBB( $str );
echo $str;

class Test
{
  var $str;
  
  function Test()
  {
    // constructor
  }
  
  function ProcessBB( $str )
  {
    $this->str = $str;
    $this->str = preg_replace( '/(\\[b\\])(.+)(\\[\\/b\\])/eisU', "$this->BoldMe('$2')", $this->str );
    return $this->str;
  }
  
  function BoldMe( $s )
  {
    return ( '<strong>'.$s.'</strong>' );
  }
}
?>


Nothing in the string will be in bold! The funny thing is that I can get it to work if function BoldMe(str) is a regular function outside the class!
  #2  
Old 31-May-2003, 09:11
Allowee's Avatar
Allowee Allowee is offline
Regular Member
 
Join Date: May 2003
Location: The Netherlands
Posts: 339
Allowee has a spectacular aura about
this works fine for me on PHP 4.3.3-dev

and it's without the 'e' and it works fine.
btw, you or your host should update there php version.
PHP 4.3.2 is already 2 days old...

Code:
$this->str = preg_replace("/(\[b\])(.+)(\[\/b\])/isU", $this->BoldMe('\\2'), $this->str);
(php tags messup the \\2)
__________________
Pastebin
PHP Documentation Site
Allowee's Blog http://allowee.net
  #3  
Old 01-Jun-2003, 00:01
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
You know what, you're absolutely right. It works without the 'e' modifier! Thank you
 
 

Recent GIDBlogAccepted for Ph.D. program by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Php bbcode issue Caged MySQL / PHP Forum 3 06-Aug-2003 19:55

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 05:54.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.