Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
How to filter url out of a string?
Old 10-02-2009, 09:38 PM How to filter url out of a string?
Junior Talker

Posts: 1
Trades: 0
hello I have a string of text with spaces in it and 4 urls in it. Each of the 4 urls changes for each string of text and I want a piece of code which extracts the 3rd url.

I know of the preg_match function but I am unable to get this working.

Please help me, any ideas welcomed dearly

Thanks
silverbullet is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-03-2009, 07:11 AM Re: How to filter url out of a string?
Average Talker

Posts: 24
Location: Germany
Trades: 0
Hi silverbullet,

I just wrote some code for you:
PHP Code:
<?php
$sampletext 
'http://us.php.net  other things http://www.webmaster-talk.com/ http://google.com another/piece of#unrelevant text http://muscularbrain.com';
$split explode(' ',$sampletext);
$counter 1;

for( 
$i 0$i<sizeof($split); ++$i)
{
    if(
substr_count($split[$i],'http://'))
    {
        if(
$counter == 3) echo $split[$i];
        ++
$counter;
    }
}
?>
Note that I assumed that everything starting with "http://" is an URL. You might want to add some exceptions, depending on your string of text.
__________________

Please login or register to view this content. Registration is FREE
- Register Now and Share Your Thoughts to Create Innovation and Wisdom


Please login or register to view this content. Registration is FREE
- Psychology, Philosophy and Self Development


Please login or register to view this content. Registration is FREE
- Read About All Those Things That Bug Me
Trey Walter is offline
Reply With Quote
View Public Profile Visit Trey Walter's homepage!
 
Old 10-03-2009, 12:12 PM Re: How to filter url out of a string?
Average Talker

Posts: 23
Name: Mary North
Trades: 0
As far as I know you can't use http:// in your url.
__________________

Please login or register to view this content. Registration is FREE
marynorth21 is offline
Reply With Quote
View Public Profile
 
Old 10-06-2009, 12:39 PM Re: How to filter url out of a string?
rednimaT's Avatar
Skilled Talker

Posts: 64
Name: Taminder B.
Location: San Jose, CA
Trades: 0
have it read the whole thing, then have it search everything that starts with www.*

then you can count out the third and echo it

oh I guess Trey Walter already made the code. sorry I'm on my iPhone =p
__________________

Please login or register to view this content. Registration is FREE

(HTML/PHP/MySQL/JavaScript/AJAX/SEO)
rednimaT is offline
Reply With Quote
View Public Profile Visit rednimaT's homepage!
 
Reply     « Reply to How to filter url out of a string?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.41993 seconds with 12 queries