Jump to content

Archived

This topic is now archived and is closed to further replies.

Darkness Soul

eregi_replace () ;

Recommended Posts

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

Share this post


Link to post
Share on other sites
[code]$str = '[http://www.phpfreaks.com/]';
$str = trim($str, '[]');
echo '<a href="' . $str . '">' . $str . '</a>';
[/code]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.