Re: [PHP] How to find img tag and get src of image
Use preg_match_all Think this will work. But i'm for sure no regular expresion guru :) preg_match_all(/src=(.*)\040/i, $Text, $Result); print_r($Result); Gr, Thijs Hi everybody! I want to get src of image form a $text, I have a below text $Text = table border=1 cellpadding=3% cellspacing=3% width=100% trtd width=20% img align=middle border=0 id=userupload/78/Autumn.jpg src=userupload/78/Autumn.jpg onClick=javascript:ViewImage(this.id); width=100 height=100 /td td/td/tr /table /td td class=frame2_middle_right/td /tr tr td class=frame2_bottom_left/td td class=frame2_bottom_center /td -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to find img tag and get src of image
On Mon, 2006-04-24 at 07:30 +0700, Pham Huu Le Quoc Phuc wrote: Hi everybody! I want to get src of image form a $text, I have a below text Regex - there is one for exactly that on http://fsiu.uwc.ac.za check out the wiki page of regular expressions. --Paul -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Jay- RE: [PHP] How to find img tag and get src of image
--- Jay Blanchard [EMAIL PROTECTED] wrote: [snip] Hi everybody! I want to get src of image form a $text, I have a below text $Text = table border=1 cellpadding=3% cellspacing=3% width=100% trtd width=20% img align=middle border=0 id=userupload/78/Autumn.jpg src=userupload/78/Autumn.jpg onClick=javascript:ViewImage(this.id); width=100 height=100 /td td/td/tr /table /td td class=frame2_middle_right/td /tr tr td class=frame2_bottom_left/td td class=frame2_bottom_center /td [/snip] And I want a pony! RTFM http://www.php.net/regex Jay, a warning would be nice before you post stuff like you posted above... I am _supposed_ to be working here and suddenly when I burst into laughter and then control myself to a big smile on my face everyone looks at me and thinks I am not working but just goofing off on the job. Cheers! -- - The faulty interface lies between the chair and the keyboard. - Creativity is great, but plagiarism is faster! - Smile, everyone loves a moron. :-) __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] RE: Jay- RE: [PHP] How to find img tag and get src of image OT
[snip] I want to get src of image form a $text And I want a pony! Jay, a warning would be nice before you post stuff like you posted above... I am _supposed_ to be working here and suddenly when I burst into laughter and then control myself to a big smile on my face everyone looks at me and thinks I am not working but just goofing off on the job. [/snip] PHP Comic Relief! Send in your money now! I will see if I can conjure up an appropriate disclaimer. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to find img tag and get src of image
On Apr 23, 2006, at 10:10 PM, Paul Novitski wrote: At 05:30 PM 4/23/2006, Pham Huu Le Quoc Phuc wrote: I want to get src of image form a $text, I have a below text $Text = table border=1 cellpadding=3% cellspacing=3% width=100% trtd width=20% img align=middle border=0 id=userupload/78/Autumn.jpg src=userupload/78/Autumn.jpg onClick=javascript:ViewImage(this.id); width=100 height=100 /td td/td/tr /table /td td class=frame2_middle_right/td /tr tr td class=frame2_bottom_left/td td class=frame2_bottom_center /td Pham, Before you do anything else, fix your HTML syntax which is full of errors. Your /table tag appears in the middle of the table and your id syntax is invalid: id=userupload/78/Autumn.jpg The specification for id [1] says it's an element of type 'name' [2]: quote ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens (-), underscores (_), colons (:), and periods (.). /quote In other words, you can't have slashes in your id. Put your HTML through the W3C markup validator before trying to write script that parses it: http://validator.w3.org/ When you're ready, you can locate an image src using a Regular Expression such as this: /img\s+[^]*src=\([^])*[^]*\/ which means: img\s+ = img followed by one or more whitespace characters [^]* = zero or more characters not including a close-bracket src=\ = src= ([^])* = zero or more characters not including a close-quote (THIS IS YOUR SRC VALUE) \ = close-quote [^]* = any number of characters excluding close-bracket = close-bracket The src attribute value will be captured by $aMatches[1] by the logic: $sRegExp = hdRE /img\s+[^]*src=\([^])*[^]*\/ hdRE; preg_match($sRegExp, $sText, $aMatches); This RegExp is designed to confine its result to a single HTML IMG tag. Documentation on PHP regular expression processing begins here: http://php.net/pcre Regards, Paul [1] specification for 'id': http://www.w3.org/TR/html4/struct/ global.html#adef-id [2] element type 'name': http://www.w3.org/TR/html4/types.html#type- name Paul, I think you are too kind. I think my response would have been likes Jay's... RTFM. However, you went above and beyond. Isn't this listserv great!! =D ~Phil -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] RE: Jay- RE: [PHP] How to find img tag and get src of image OT
--- Jay Blanchard [EMAIL PROTECTED] wrote: [snip] I want to get src of image form a $text And I want a pony! Jay, a warning would be nice before you post stuff like you posted above... I am _supposed_ to be working here and suddenly when I burst into laughter and then control myself to a big smile on my face everyone looks at me and thinks I am not working but just goofing off on the job. [/snip] PHP Comic Relief! Send in your money now! I will see if I can conjure up an appropriate disclaimer. Send in your money now!!!?? ok, stopped laughing. -- - The faulty interface lies between the chair and the keyboard. - Creativity is great, but plagiarism is faster! - Smile, everyone loves a moron. :-) __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] How to find img tag and get src of image
[snip] Hi everybody! I want to get src of image form a $text, I have a below text $Text = table border=1 cellpadding=3% cellspacing=3% width=100% trtd width=20% img align=middle border=0 id=userupload/78/Autumn.jpg src=userupload/78/Autumn.jpg onClick=javascript:ViewImage(this.id); width=100 height=100 /td td/td/tr /table /td td class=frame2_middle_right/td /tr tr td class=frame2_bottom_left/td td class=frame2_bottom_center /td [/snip] And I want a pony! RTFM http://www.php.net/regex -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to find img tag and get src of image
At 05:30 PM 4/23/2006, Pham Huu Le Quoc Phuc wrote: I want to get src of image form a $text, I have a below text $Text = table border=1 cellpadding=3% cellspacing=3% width=100% trtd width=20% img align=middle border=0 id=userupload/78/Autumn.jpg src=userupload/78/Autumn.jpg onClick=javascript:ViewImage(this.id); width=100 height=100 /td td/td/tr /table /td td class=frame2_middle_right/td /tr tr td class=frame2_bottom_left/td td class=frame2_bottom_center /td Pham, Before you do anything else, fix your HTML syntax which is full of errors. Your /table tag appears in the middle of the table and your id syntax is invalid: id=userupload/78/Autumn.jpg The specification for id [1] says it's an element of type 'name' [2]: quote ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens (-), underscores (_), colons (:), and periods (.). /quote In other words, you can't have slashes in your id. Put your HTML through the W3C markup validator before trying to write script that parses it: http://validator.w3.org/ When you're ready, you can locate an image src using a Regular Expression such as this: /img\s+[^]*src=\([^])*[^]*\/ which means: img\s+ = img followed by one or more whitespace characters [^]* = zero or more characters not including a close-bracket src=\ = src= ([^])* = zero or more characters not including a close-quote (THIS IS YOUR SRC VALUE) \ = close-quote [^]* = any number of characters excluding close-bracket = close-bracket The src attribute value will be captured by $aMatches[1] by the logic: $sRegExp = hdRE /img\s+[^]*src=\([^])*[^]*\/ hdRE; preg_match($sRegExp, $sText, $aMatches); This RegExp is designed to confine its result to a single HTML IMG tag. Documentation on PHP regular expression processing begins here: http://php.net/pcre Regards, Paul [1] specification for 'id': http://www.w3.org/TR/html4/struct/global.html#adef-id [2] element type 'name': http://www.w3.org/TR/html4/types.html#type-name -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php