1

I have a text/sentence I am pulling from another site.

[random/changing text] valid from [time] to [time]

Example:

partly cloudy valid from 8th of May to 9th of May

I want to have a .<br> tag before the word valid from which is static (the other words are not, nor the length). I guess I need to search in the sting for the specific word valid or break the sentence up into parts since I can't count letter etc. Any way to do this with PHP and HTML? Thanks in advance

andreasv
  • 450
  • 1
  • 4
  • 15

1 Answers1

0

A correct answer is already in the comments. I'll just add an explanation here to make sure the question is correctly counted as answered.

You could search for the position of "valid" in your string, extract its index, break the string apart and insert your br statement. But the solution using str_replace is just so much cleaner. You just replace the word valid with br valid, effectively inserting your br at the right position of the string.

Be aware though, that you might run into problems when using multibyte character sets. See this Stack Overflow question for an explanation.

Markus Müller
  • 2,611
  • 1
  • 17
  • 25