Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

convert a part of text into html format?

Status
Not open for further replies.

hisham

IS-IT--Management
Nov 6, 2000
194
In mysql database I have a field its name: content, type: text , my question: what is the code or how to convert a part of this text into html format? i.e. if the field contain the following text:
Please visit my site .
So I need to convert into link to the specific url.
Thanks in advance.
 
Hi Hisham. this may be part of the solution you're looking for. it works fine but you must know the name of the URL which is in the string.


<?php

$originalstring = &quot;The URL is Please click the link&quot;;
$newstring = str_Replace(&quot; href=' ,$originalstring);

echo $newstring;


?>


I am investigating ways of searching the string for any web addresses and automatically replacing them, but the above code might help you for now. :) Nick (Web Developer)


nick@retrographics.co.uk
 
There was a thread in which a preg_replace was posted that will convert any email and into links. Though I was unable to find it, so I will make an attempt to make a regexp that should work:
$content = preg_replace(&quot;!(([A-Za-z0-9\-\.]+\.)?[A-Za-z0-9\-\.]+\.[A-Za-z\.]{2,5}(/[A-Za-z0-9\-\._ ]+)?)!&quot;, &quot;<a href=\&quot;\\1\&quot;>\\1</a>&quot;, $content);
I hope this gets you started, at least. //Daniel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top