Jump to content

Simplifying a function.


haku

Recommended Posts

I need to strip the space from the text inside an anchor tag, and replace it with a <br /> tag. I am using this code right now:

 

$link = '<a href="this/is.html">This is a link</a>';
$text = strip_tags($link);

$converted_text = str_replace(' ','<br />',$text);
echo str_replace($text,$converted_text,$link);

 

It works just fine. But I'm thinking there should be a way to simplify it into using one function using regex, or maybe some other way. But I'm crap at regex and I can't think of another way.

 

Anybody want to take a stab as simplifying it?

Link to comment
https://forums.phpfreaks.com/topic/135444-simplifying-a-function/
Share on other sites

Archived

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

×
×
  • 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.