SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    preg_replace problem

    I can't seem to get this piece of code to work

    This:
    PHP Code:
    $text=preg_replace("/(\[feature=(.*?)\])/ie","singleArticle($paper_id,$issue_id,$1)",$text); 
    Gives me this:
    PHP Code:
    Parse errorparse errorunexpected '[' in /home/blongle/public_html/functions.php(164) : regexp code on line 1

    Fatal error
    Failed evaluating codesingleArticle(1,1,[feature=Redsox Win Against Yankees]) in /home/blongle/public_html/functions.php on line 164 
    Any ideas?
    Nick . all that we see or seem, is but a dream within a dream
    Show someone you care, send them a virtual flower.
    Good deals on men's watches

  2. #2
    Non-Member coo_t2's Avatar
    Join Date
    Feb 2003
    Location
    Dog Street
    Posts
    1,819
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    I got the same error. I don't know why.
    I'd try using a callback like:

    PHP Code:
      
      <?php
      
      $paper_id 
    1;
      
    $issue_id 1;
      
      
    $text '[feature=Redsox Win Against Yankees]';
      
      
    $text=preg_replace_callback("/(\[feature=(.*?)\])/i"'do_replace'$text );
      
      
      function 
    do_replace($matches)
      {
          
    // I don't like doing this, but I reckon you have to use "GLOBAL" in 
          // this circumstance
          
    GLOBAL $paper_id$issue_id;
      
          
    #var_dump('matches', $matches);
      
          // use $matches to send whatever captured element you want to singleArticle
          
    singleArticle($paper_id$issue_id$matches[2]);
      }
      
      
      function 
    singleArticle($paper_id$issue_id$text)
      {
          
    var_dump('in singleArticle()'$paper_id$issue_id$text);
      }
      
      
    ?>

    --ed


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
  •