SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Evangelist
    Join Date
    Apr 2003
    Location
    Chicago, USA
    Posts
    417
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    preg_replace Help (Again)

    I can't get this to work the way I want it to:

    Code:
    $contents = preg_replace ("#(\\\$Settings?)\['([a-z0-9_]+?)'\]#eis",   $this->settings['$2'], $contents);
    Basically, if $Settings['someElement'] (literal text, not value of it) is found within $contents, then $Settings['someElement'] is replaced with $this->settings['someElement'] (the value of it, not literal text). So say that:

    $this->settings['test'] = "Blah";

    If in $contents, "$Settings['test']" is found, then it would be replaced with 'Blah'.

    Hope I didn't confuse anyone, and thanks for any help in advance.

  2. #2
    SitePoint Evangelist
    Join Date
    Apr 2003
    Location
    Chicago, USA
    Posts
    417
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    *Bump*

  3. #3
    SitePoint Evangelist
    Join Date
    Apr 2003
    Location
    Chicago, USA
    Posts
    417
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I guess no one knows how to do this?

  4. #4
    SitePoint Zealot
    Join Date
    Dec 2001
    Location
    UK
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You mean something like this
    PHP Code:
     $element 'a scalar';
      
    $contents "This is a test with \$Settings['element'] included";
      
    $contents preg_replace ('/(\$Settings\[\'(.+)\'\])/e'"$\{$2}"$contents);
      echo 
    "$contents"

  5. #5
    SitePoint Evangelist
    Join Date
    Apr 2003
    Location
    Chicago, USA
    Posts
    417
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by torrent
    You mean something like this
    PHP Code:
     $element 'a scalar';
      
    $contents "This is a test with \$Settings['element'] included";
      
    $contents preg_replace ('/(\$Settings\[\'(.+)\'\])/e'"$\{$2}"$contents);
      echo 
    "$contents"
    Doesn't work.

    Yeah, basically this is what's going on:

    Code:
    class SomeClass
    {
       var $someArray = array('test' => 'test');
    
       function Parse ($template)
       {
          return preg_replace ("#\\\$SomeArray\['([a-z0-9_]+?)'\]#eis", "{$this->someArray['$1']}", $template);
       }
    }
    
    $template = "Blah blah blah \$SomeArray['test'] blah blah blah";
    
    $SomeClass = new SomeClass();
    $template = $SomeClass->Parse($template);
    
    echo $template
    
    // Result should be:
    // Blah blah blah test blah blah blah
    Hopefully that will help other people understand my problem better. Thanks for the help so far.

  6. #6
    SitePoint Evangelist
    Join Date
    Apr 2003
    Location
    Chicago, USA
    Posts
    417
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anyone else?

  7. #7
    SitePoint Evangelist
    Join Date
    Apr 2003
    Location
    Chicago, USA
    Posts
    417
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ...

  8. #8
    SitePoint Evangelist
    Join Date
    Apr 2003
    Location
    Chicago, USA
    Posts
    417
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Bumping this one more time...


Bookmarks

Posting Permissions

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