Darkness Soul Posted August 14, 2006 Share Posted August 14, 2006 Yo,I need a little help.. I'm supose to read from a file an url and show it as well.. like it:[code]:BOF:[http://www.phpfreaks.com/]:EOF:[/code]So, I need to remove these [ and ] to build something like:[code]<a href="http://www.phpfreaks.com/">http://www.phpfreaks.com/</a>[/code]I've tried eregi_replace, but I'm not good with regular expressions yet.. :(Thanks for any help..D.Soul Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted August 14, 2006 Share Posted August 14, 2006 [code]$str = '[http://www.phpfreaks.com/]';$str = trim($str, '[]');echo '<a href="' . $str . '">' . $str . '</a>';[/code] Quote Link to comment Share on other sites More sharing options...
Caesar Posted August 14, 2006 Share Posted August 14, 2006 This will work:[code]<?php$contents = ':BOF: [http://www.phpfreaks.com/] :EOF:';preg_match("/(http:\/\/)[a-zA-Z0-9-]+[\._a-zA-Z0-9-]+/i", $contents, $links);echo"<a href=\"$links[0]\">$links[0]</a>";?>[/code] Quote Link to comment Share on other sites More sharing options...
Darkness Soul Posted August 15, 2006 Author Share Posted August 15, 2006 Yo,[quote author=hitman6003 link=topic=104258.msg415767#msg415767 date=1155590341][code]$str = '[http://www.phpfreaks.com/]';$str = trim($str, '[]');echo '<a href="' . $str . '">' . $str . '</a>';[/code][/quote]Yeah, but this isn't the way i need it.. [quote author=Caesar link=topic=104258.msg415770#msg415770 date=1155590636]This will work:[code]<?php$contents = ':BOF: [http://www.phpfreaks.com/] :EOF:';preg_match("/(http:\/\/)[a-zA-Z0-9-]+[\._a-zA-Z0-9-]+/i", $contents, $links);echo"<a href=\"$links[0]\">$links[0]</a>";?>[/code][/quote]This help too, but what i need is to replace that url inside a variable with the text line, so, when I print that line, its print the link as well.. and not the url alone..=)an expemple:$var = 'this is the text line with [http://www.test.com] or [url=http://www.test.com]http://www.test.com[/url] url inside' ;the trim method don't leave to print this line with the second link.. and the [url][/url] is a better way to me to keep the url safe.. so, i think about use preg_replace, based on your post, caesar..Bye, D.Soul Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.