calculataur
calculataur

Reputation: 171

PHP preg_replace first space char from a tag

I have this link html code: <a href="/drupal-7.41/en/node/3" title="">Lorem Ipsum Dolor</a> I need to replace the first space between the a tag with a <br />

So the result should look like: <a href="/drupal-7.41/en/node/3" title="">Lorem<br />Ipsum Dolor</a>

I tried something like (?:<.*">.*)(\s) but without any success.

Upvotes: 0

Views: 61

Answers (1)

Jorge Campos
Jorge Campos

Reputation: 23381

Try this way:

(<a[^>]*>)(.+?)(\s)(.+)(<\/a>)

And replace it by:

$1$2<br />$4$5

See it working here: https://regex101.com/r/sI4cI9/2

Upvotes: 1

Related Questions