replacement within a string

Posted on 2006-05-02
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:

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.
Question by:sushestvo
    LVL 49

    Expert Comment

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

    LVL 1

    Author Comment

    it doesn't really work... especially with multiple pics on in the $string
    or even with this (
    it leaves "-102784.jpg" behind.
    Is it possible to cut out everything between http and jpg ?
    LVL 49

    Accepted Solution

    That's fairly easy:

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


    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
    Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to dynamically set the form action using jQuery.

    734 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now