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
Wrap <a> around link without [url=]
Old 09-06-2008, 08:26 PM Wrap <a> around link without [url=]
Galaxian's Avatar
Rich Powell

Posts: 842
Name: Rich Powell
Location: United Kingdom
Trades: 0
Forgive me for my tiredness at this hour, but how'd you guys go about parsing a URL (e.g http://link/) and wrapping it into <a href="http://link/">http://link/</a> if it isn't already wrapped in and isn't a part of example ?
__________________

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

Please help get the new
Please login or register to view this content. Registration is FREE
forum started for Webmasters like you!

Galaxian is offline
Reply With Quote
View Public Profile Visit Galaxian's homepage!
 
 
Register now for full access!
Old 09-07-2008, 06:12 AM Re: Wrap <a> around link without [url=]
Skilled Talker

Posts: 85
Name: Ilyes Rhouma
Trades: 0
This will never be easy
You may search for "http://" with strpos(), then search for the next space character, then all between them is the url, then add <a href="...

I think this will be like this: not tested.
PHP Code:
$text "all the text here, go to http://someurl/thefile.php ok."
$pos1=strpos($text"http://" );
$pos2=strpos($text" "$pos1) ;
$link substr($text$pos1pos2-$pos1) ;
$newtext str_replace($link,'<a href="' $link '>' $link '</a>'$text );
echo 
$newtext 
Note: This is a quick script that need many fixes, like if in one situation the url will not be ended with a space,...
__________________
Want a cheap and custom programmer or writer ?
Please login or register to view this content. Registration is FREE

Are you
Please login or register to view this content. Registration is FREE
? Start
Please login or register to view this content. Registration is FREE
free and earning money !
Please login or register to view this content. Registration is FREE

Last edited by Ilyes; 09-07-2008 at 06:15 AM..
Ilyes is offline
Reply With Quote
View Public Profile Visit Ilyes's homepage!
 
Old 09-07-2008, 07:42 AM Re: Wrap <a> around link without [url=]
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
and of course it will "break" if the filename / url has spaces in it.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-07-2008, 08:32 AM Re: Wrap <a> around link without [url=]
Galaxian's Avatar
Rich Powell

Posts: 842
Name: Rich Powell
Location: United Kingdom
Trades: 0
That failed terribly
__________________

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

Please help get the new
Please login or register to view this content. Registration is FREE
forum started for Webmasters like you!

Galaxian is offline
Reply With Quote
View Public Profile Visit Galaxian's homepage!
 
Old 09-08-2008, 11:35 AM Re: Wrap <a> around link without [url=]
Skilled Talker

Posts: 85
Name: Ilyes Rhouma
Trades: 0
So ? Someone have another solution ?

PS: I forget ";" at the end of the first line, and "$" for "$pos2" in line four, now fixed here, try again.
PHP Code:
$text "all the text here, go to http://someurl/thefile.php ok.";
$pos1=strpos($text"http://" );
$pos2=strpos($text" "$pos1) ;
$link substr($text$pos1$pos2-$pos1) ;
$newtext str_replace($link,'<a href="' $link '>' $link '</a>'$text );
echo 
$newtext 
This will works for the first url, if it's ok, I will make it do so for all urls in the text..

Quote:
and of course it will "break" if the filename / url has spaces in it.
Spaces in urls are always replaces with %20 ( or something like that)

http://www.google.com/file1.html
http://www.google.com/file 1.html

Like in this forum, " it will "break" if the filename / url has spaces in it. "
__________________
Want a cheap and custom programmer or writer ?
Please login or register to view this content. Registration is FREE

Are you
Please login or register to view this content. Registration is FREE
? Start
Please login or register to view this content. Registration is FREE
free and earning money !
Please login or register to view this content. Registration is FREE

Last edited by Ilyes; 09-08-2008 at 01:18 PM..
Ilyes is offline
Reply With Quote
View Public Profile Visit Ilyes's homepage!
 
Old 09-08-2008, 01:22 PM Re: Wrap <a> around link without [url=]
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Yep,
so the challenge is on to find a regular expression that doesn't
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-08-2008, 06:03 PM Re: Wrap <a> around link without [url=]
Galaxian's Avatar
Rich Powell

Posts: 842
Name: Rich Powell
Location: United Kingdom
Trades: 0
BB Code Input:

Code:
http://www.testlink.org/

test test

test
HTML Output (firefox source viewer):

Code:
<p><a>http://www.testlink.org/</a></p>

<p><a></a> href="http://www.testlink.org"&gt;test test</p>

<p>test</p>
__________________

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

Please help get the new
Please login or register to view this content. Registration is FREE
forum started for Webmasters like you!

Galaxian is offline
Reply With Quote
View Public Profile Visit Galaxian's homepage!
 
Reply     « Reply to Wrap <a> around link without [url=]
 

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.19288 seconds with 12 queries