/    Sign up×
Community /Pin to ProfileBookmark

Ok I am sure someone has asked a similar question before but I couldn’t find anything.

I want to do the following.

Change

[CODE]
<a href=”http://www.bbc.co.uk/”>The BBC Website</a>
[/CODE]

to

[CODE]
The BBC Website
http://www.bbc.co.uk
[/CODE]

Can anyone help me?

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@ellisglAug 02.2007 — You can do with preg_split.. but i'm having some issues with my regex coding..

This code is wrong but close:
[code=php]
<?php
$link = '<a href="http://www.bbc.co.uk/">The BBC Website</a>';
$url = preg_split('/<a href="http://.*?/">/', $link);
$title = preg_split('//>.*?<//', $link);
print_r($url);
echo '<br />';
echo $title[0],'<br />',$url[1];
?>
[/code]
Copy linkTweet thisAlerts:
@ellisglAug 02.2007 — ok - this works:
[code=php]
<?php
$link = '<a href="http://www.bbc.co.uk/">The BBC Website</a>';
$arr = split('"', $link);
$url = strip_tags($arr[1]);
$title = split('>', $arr[2]);
echo rtrim($title[1],'</a'),'<br/>',$url;
?>
[/code]
Copy linkTweet thisAlerts:
@NogDogAug 03.2007 — [code=php]
<?php
$text = '<a href="http://www.bbc.co.uk/">The BBC Website</a>';
$regex = '#<as[^>]*href=["']([^"']+)["'][^>]*>([^<]+)</a>#i';
$output = preg_replace($regex, '\2<br />\1', $text);
echo $output;
[/code]
Copy linkTweet thisAlerts:
@ellisglAug 03.2007 — There we go! My RegEx knowledge is horrible. It took me a couple days to figure out an issue that dealt with RegEx.

http://www.regular-expressions.info/tutorial.html -- made me more confused.

http://www.regexbuddy.com/ was the best in helping me on that..

There is http://weitz.de/regex-coach/ also
×

Success!

Help @stephan_gerlach spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...