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

Nice, thanks. That's exactly what I was looking for. Nice little regex - I'm going to spend a bit of time looking at how it works.

 

Regex is something I've been trying to pick up for a while, but I'm still not very good at it.

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.