FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Extracting multiple matches from a string using preg_replace
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Extracting multiple matches from a string using preg_replace [message #178587 is a reply to message #178584] Mon, 09 July 2012 19:00 Go to previous messageGo to previous message
jwcarlton is currently offline  jwcarlton
Messages: 76
Registered: December 2010
Karma:
Member
On Monday, July 9, 2012 9:29:15 AM UTC-4, Peter H. Coffin wrote:
> That's the drawback to using preg_replace() for this. You can't capture
> all the bits you want to extract because you *must* enumerate them.
> preg_match_all() returns an array of matches, which is what you want if
> you don't know how many you're going to get back going in.

Thanks, I'll modify the script this evening with preg_match_all(). :-D


>> // I'm not sure why preg_replace isn't catching the extra variables;
>> // I thought the [&.+]* would do this? Either way, this is a
>> workaround: list($this_id) = explode("&", $this_id);
>
> Define "catching" in this context. If you want it back, you need to
> paren-tag it so it goes into an enumerated output slot.

No, I mean that it's not removing the additional variables. So, this:

&feature=related

Returns this as $this_id:

123456&feature=related

when I just want the "123456".
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Invitacion a INFOSOFT 2012 [PUCP]
Next Topic: PHP does not flush output on IIS7 ..
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Tue Nov 26 09:45:55 GMT 2024

Total time taken to generate the page: 0.04332 seconds