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

Recommended Answers

All 8 Replies

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

hello... you have several options to implement this. use preg_replace function or use parse_url function. below i have explained it further.

$tempText = "hello.. how are you?? are you keeping well?? please checkout this url http://www.youtube.com/watch?v=ehuwoGVLyhg&feature=topvideos";

print_r(parse_url($tempText,PHP_URL_PATH));

hope this would be useful.
Thanks!
Asoka

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.