i have a long string which contains a url. I want to extract that url from that particular string. Please help me.

i have a long string which contains a url. I want to extract that url from that particular string. Please help me.

Hi ditty....

U can extract by using this way....

1) by using EXPLODE function
2)by using SPLIT function...

eg:

$url="http://info@abc.com";
list(first,second)=split("@",$url,2)
echo $second;

or

$a=explode('@',$url);
$a[1];

sorry....i mean i have a string for example

ssfihuihuiifhhdfhishfihfh jjjjjif ee@gg.com jfiosofjojofjjm ojofjojfc ojjofjojw

From this i want to extract ee@gg.com

If the string is in this format

aaaaaaaaaabbbbbbbbbbcccccmail@yahoo.comdddddddeeeeeeeffff

I don't think you can extract the email address, since you wouldn't know what is the exact part before @. If your string is as you stated above, ie.,

ssfihuihuiifhhdfhishfihfh jjjjjif ee@gg.com jfiosofjojofjjm ojofjojfc ojjofjojw

then you can explode the string to an array, then check each array element (with regular expression), if it contains a valid email address.

sorry....i mean i have a string for example

ssfihuihuiifhhdfhishfihfh jjjjjif ee@gg.com jfiosofjojofjjm ojofjojfc ojjofjojw

From this i want to extract ee@gg.com

Hi..

can u try to using SUBSTRING FUNCTIONS ..i dont know the exact solution..but, if string having hdgfhgfgjh http://aaaa@g.com hdgfhdgfhdfg ....than u can do...ok...

any body knows good solution,plz solve this one...

Hi,

First explode the string " hdgfhgfgjh http://aaaa@g.com hdgfhdgfhdfg " by using " " (space).....

There at one extent you will find the URL (i.e) Explode will return an array.....

By checking an array element with preg_match() to find the URL....

Once you found the URL, break the loop


Regards,
Fatty

<?php

    $originalString = "ssfihuihuiifhhdfhishfihfh jjjjjif [email]ee@gg.com[/email] jfiosofjojofjjm ojofjojfc ojjofjojw ";

    $stringToArray= explode(" ",$originalString);

    echo "<pre>".print_r($stringToArray,1)."</pre>";

    foreach($stringToArray as $key=>$val){
        $URL_Validation=ereg("^[^@ ]+@[^@ ]+\.[^@ ]+$",$val,$trashed);
        if($URL_Validation){
            $URL = $val;
            break;
        }
    }

    echo "URL : ".$URL;

?>

Hope this code will help u :)

Regards,
Fatty

Edited 3 Years Ago by mike_2000_17: Fixed formatting

This article has been dead for over six months. Start a new discussion instead.