www.webdeveloper.com
Results 1 to 2 of 2

Thread: How to make a subpattern replace with number directly after?

  1. #1
    Join Date
    Nov 2010
    Posts
    66

    How to make a subpattern replace with number directly after?

    Here is my code:
    Code:
    $string = '<a href="a.php?id=">sometext</a>';
     $result = (preg_replace('/(.+href=)"(.+\..+)"/i', '$1"$2abc"', $string) );
    My goal is to give this url (id=) a value. Using the code above ill get the value "abc". Anytime I change "abc" to any int value it doesnt work. For example if I say $21 it will think I want to use the subpattern 21 instead of using subpattern 2 then add a single "1". I tried ascii in the replace without any luck...

    edit: well one way I csan bypass this problem in this scenario:
    Code:
     $result = (preg_replace('/(.+href=)"(.+\..+)="/i', '$1"$2=1"', $string) );
    I am still looking for a real fix to this problem tho.
    Last edited by ZeratulsDomain; 02-28-2012 at 08:22 PM.

  2. #2
    Join Date
    Nov 2010
    Posts
    66
    bump?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles