?
Solved

replacement within a string

Posted on 2006-05-02
3
Medium Priority
?
197 Views
Last Modified: 2008-03-03
I have a string that could be up to 8000 characters.
String is a text with pictures and stuff like that.
How can I do a replace on the string to cut out everything that is an email, I mean that looks like this:
http://someurl/folder/anotherfolder/whatever/name.jpg
or
http://someurl/folder/anotherfolder/whatever/name.gif

Pretty much I want to remove all the pics from the $string.
I guess it would be preg_replace with regexp?
But I have no clue how to do this. Please someone help.
0
Comment
Question by:sushestvo
  • 2
3 Comments
 
LVL 49

Expert Comment

by:Roonaan
ID: 16587950
$preg = '#http://[\w/\.]+#i';
$replace = '';
$string = preg_replace($preg, $replace, $string);

-r-
0
 
LVL 1

Author Comment

by:sushestvo
ID: 16595979
it doesn't really work... especially with multiple pics on in the $string
or even with this (http://images.ciao.com/ide/images/products/normal/784/product-102784.jpg)
it leaves "-102784.jpg" behind.
Is it possible to cut out everything between http and jpg ?
0
 
LVL 49

Accepted Solution

by:
Roonaan earned 2000 total points
ID: 16596349
That's fairly easy:

$preg = '#http://(.*)\.(jpg|jpeg|gif|png)#i';

-r-
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month17 days, 3 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question