Reputation: 7056
How can I trim white space between two specific characters in the same string? i.e. I just want to close the space between the first tag there and the start of the next word...
I want to turn this:
<code>
testing testing 123
test
into this:
<code>testing testing 123
test
The <code>
will always be there, so perhaps I could use that as some sort of anchor point?
Thanks
Upvotes: 2
Views: 998
Reputation: 4456
Assuming <code>
always exists at the beginning of your string, you can use:
$str = preg_replace( '/^<code>\s+/', '<code>', $str )
The regular expression above will match a <code> tag at the beginning of a line (the ^ indicator) and remove all whitespace characters following it (the \s+) pattern.
Upvotes: 1
Reputation: 10176
Use RegExp, something like this:
$trimmed = preg_replace('/(<[^>]*>)\s*/', '\1', $input_string)
This will work on ANY html-tag ;)
Upvotes: 0
Reputation: 6117
$trimmed = trim(substr($in, 6));
that will remove the whitespace after <code>
up to the first non-whitespace.
Upvotes: 2