Jump to content

eregi_replace () ;


Darkness Soul

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.