Activity Stream
48,167 MEMBERS
6966 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Results 1 to 2 of 2
  1.     
    #1
    Member
    Website's:
    maxneeds.info

    Post preg_replace first half of matches ?

    Hi !
    I was wondering if it is possible to replace the first half of matches using only preg_replace ?

    Like i have
    Code: 
    [img=some1]
    [img=some2]
    [img=some3]
    [img=some4]
    PHP Code: 
    $pattern='(\[img=(.*?)\])';
    $test=preg_replace($pattern,'replaced',$test);
    echo 
    $test
    The above code gives:
    Code: 
    [img=replaced]
    [img=replaced]
    [img=replaced]
    [img=replaced]
    RESULT WANTED
    Code: 
    [img=replaced]
    [img=replaced]
    [img=some3]
    [img=some4]
    PLS help !
    Porsche_maniak Reviewed by Porsche_maniak on . preg_replace first half of matches ? Hi ! I was wondering if it is possible to replace the first half of matches using only preg_replace ? Like i have Rating: 5

  2.   Sponsored Links

  3.     
    #2
    Member
    Website's:
    litewarez.net litewarez.com triniwarez.com
    People should read the manual a little more in depth:

    mixed preg_replace ( mixed $pattern , mixed $replacement , mixed $subject [, int $limit = -1 [, int &$count ]] )
    Meaning you can go:

    PHP Code: 
    $total_found preg_match_all('(\[img=.*?\])',$subject);
    $test preg_replace($pattern,'replaced',$testceil($total_found 2));
    echo 
    $test
    The 4th param is the limit variable, not to be confused with the 5th param which is count
    Join Litewarez.net today and become apart of the community.
    Unique | Clean | Advanced (All with you in mind)
    Downloads | Webmasters


    Notifications,Forum,Chat,Community all at Litewarez Webmasters


Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Preg_replace help
    By Gavo in forum Web Development Area
    Replies: 3
    Last Post: 25th Sep 2012, 07:23 PM
  2. Replace with Dynamic variable in preg_replace
    By MarPlo in forum Web Development Area
    Replies: 2
    Last Post: 21st Feb 2012, 08:36 AM
  3. Wordpress title preg_replace
    By energyboost in forum Wordpress
    Replies: 2
    Last Post: 3rd Oct 2011, 11:47 PM
  4. Lulzimg preg_replace help
    By masterb56 in forum Web Development Area
    Replies: 2
    Last Post: 15th Aug 2011, 06:31 PM
  5. Brodcasting Matches , allowed by google ads ?
    By NightMare in forum General Discussion
    Replies: 2
    Last Post: 1st Apr 2011, 03:49 PM

Tags for this Thread

BE SOCIAL