Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
PHP Regular Expression
Old 04-03-2005, 12:15 PM PHP Regular Expression
Junior Talker

Posts: 1
Trades: 0
<img alt="imagey" src="http://example.com/image.gif" width="10">

Now, what the regular expression has to do is extract only the part for the src from the image tag, meaning http://example.com/image.gif. Everything else has to be disregarded, no matter what it says before or after that.
Also, it would have to be compatible so that there are more images in a row;

<img alt="imagey" src="http://example.com/image.gif" width="10"><img alt="imagey" src="http://example.com/image.gif" width="10"><img alt="imagey" src="http://example.com/image.gif" width="10">

and that would recover the src from all of them.

Also there mayb be or may not be a " or a '. meaning it would be either:
src="IMAGELINK"
src='IMAGELINK'
src=IMAGELINK

It's been tried several times with several options but none seem to work.
This seems a bit more complicated. Any help is appreciated.
Thanks.

Last edited by wooper; 04-03-2005 at 12:19 PM..
wooper is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-03-2005, 06:57 PM
leavethisplace's Avatar
Ultra Talker

Posts: 297
Trades: 0
Well, someones demanding!

First off, the code below will not address the problem of the
Quote:
Also there mayb be or may not be a " or a '. meaning it would be either:
src="IMAGELINK"
src='IMAGELINK'
src=IMAGELINK
Mainly because i'm not sure where you are getting the string from (that is, the HTML code of the IMG SRC). One easy way to do it is simply to strip the "" or '' out of the string completely, since you wont need to return them anyway (str_replace?).

Hope this will make sense, spent a while making sure it works, so make sure you tell me how it works out!

PHP Code:
/* Just took a small chunk of the string, no point in putting it all there, see what i mean
about removing the "" or '' ? */
$string "<img alt=imagey src=http://example.com/image.gif width=10>";

/* Since we're just looking for something to do with "src=" lets search for it in the string,
remember this will only find the first occurance. And also get everything after it! */
$match strstr($string'src=');

/* so, lets get rid of everything after the src=blablabla bit. Using a space as a seperator,
although if there is a closing > after the SRC= string you're screwed, lets band away everything. */
$separat " ";
$match substr($match0strlen($match)-strlen (strstr ($match,$separat)));

/* But, we're still left with the entrailing src= bit, so tell it where to go with a nice str_replace! */
$match str_replace ("src=""""$match");

echo 
$match
Hope this helps, i know it's not perfect, but it's the best I could really do (since i wanna go to bed!) see how this works out for ya.
leavethisplace is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to PHP Regular Expression
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.10262 seconds with 12 queries