Connecting Tech Pros Worldwide Forums | Help | Site Map

finding location (start and lengh) of a substring in a bigger string.

Moham12345
Guest
 
Posts: n/a
#1: Sep 24 '07
Hi,

Im struggling here ... is it possible to check for a string pattern
like a valid url in a bigger string. And then return the matching
pattern string?

so if i had a string like : "This is my website it is called www.google.com
and i have made lots of money"
Now how can i match a url in this string.... or any url for that
matter and return it?

In this case it would return "www.google.com".

Thanks in advance.


Shelly
Guest
 
Posts: n/a
#2: Sep 24 '07

re: finding location (start and lengh) of a substring in a bigger string.



"Moham12345" <m_w_raza@hotmail.comwrote in message
news:1190642848.815082.151920@w3g2000hsg.googlegro ups.com...
Quote:
Hi,
>
Im struggling here ... is it possible to check for a string pattern
like a valid url in a bigger string. And then return the matching
pattern string?
>
so if i had a string like : "This is my website it is called
www.google.com
and i have made lots of money"
Now how can i match a url in this string.... or any url for that
matter and return it?
>
In this case it would return "www.google.com".
>
Thanks in advance.
www.php.net and look at strstr and related functions.

Shelly


Shelly
Guest
 
Posts: n/a
#3: Sep 24 '07

re: finding location (start and lengh) of a substring in a bigger string.



"Moham12345" <m_w_raza@hotmail.comwrote in message
news:1190642848.815082.151920@w3g2000hsg.googlegro ups.com...
Quote:
Hi,
>
Im struggling here ... is it possible to check for a string pattern
like a valid url in a bigger string. And then return the matching
pattern string?
>
so if i had a string like : "This is my website it is called
www.google.com
and i have made lots of money"
Now how can i match a url in this string.... or any url for that
matter and return it?
>
In this case it would return "www.google.com".
>
Thanks in advance.
You might also need to look at strtok and substr. For example, find the
postion of "www." or "http://: in the string and take the substring of
that. Then take only until the space. Alternatively, you could look at
"explode" and take the one in the array that begins with "www." or
"http://". Of course, if your URL does not begin with "www." or "http://",
then I am not sure how to do it. I would have to investigate that myself,
but you can do that homework as well as I can.

Shelly



Closed Thread