CodingRegular expressions

 

Press Ctrl+Enter to quickly submit your post
Quick Reply  
 
 
  
 From:  andy  
 To:  Ally      
30594.4 In reply to 30594.1 
php code:
$array_matches = array();
preg_match("/<img [^>]*src=\"([^\"]+)\"[^>]*>/i", $string_subject, $array_matches);
print_r($array_matches);


sorta thing. The "[^>]*>" at the end is a bit redundant as you don't actually want to do anything with that bit, but blah.
0/0
 Reply   Quote More 

 From:  Ally   
 To:  ALL
30594.5 
Crikey. Thanks everyone. I shall run a small lottery to decide which one I'll go with.
0/0
 Reply   Quote More 

 From:  Dave!!  
 To:  Ally      
30594.6 In reply to 30594.5 
I'd recommend trying Matt's and Andy's over mine as I trust their regex skills more. But you probably knew that anyway :)
---

And the Lord said unto John; Come forth and receive eternal life. But John came fifth and won a toaster instead.
0/0
 Reply   Quote More 

Message 30594.7 deleted 12 Sep 2006 21:15 by ALLY

Message 30594.8 deleted 12 Sep 2006 21:15 by ALLY

 From:  Ally   
 To:  andy     
30594.9 In reply to 30594.4 

I get an array with two elements- both one image, one with tags, one without (with yours and Matt's)

 

Have I done summat wrong?

0/0
 Reply   Quote More 

 From:  Rowan  
 To:  Ally      
30594.10 In reply to 30594.9 
Nope.
quote: php.net
If matches is provided, then it is filled with the results of search. $matches[0] will contain the text that matched the full pattern, $matches[1] will have the text that matched the first captured parenthesized subpattern, and so on.


Unless you wanted all the matches, sorry. In which case, you'd be best off using preg_match_all().

Edit: Good Lord, this post has been a bit of a massacre.

www.oforpertainingto.me.uk

0/0
 Reply   Quote More 

 From:  Ally   
 To:  Rowan     
30594.11 In reply to 30594.10 
Aharrr. So I was just being an idiot. Thankee very much.
0/0
 Reply   Quote More 

Reply to All    
 

1–11

Rate my interest:

Adjust text size : Smaller 10 Larger

Beehive Forum 1.5.2 |  FAQ |  Docs |  Support |  Donate! ©2002 - 2024 Project Beehive Forum

Forum Stats