0

Hello Everyone.

Can you please advise how can I replace a string from this "[" to "]" this character and replace it with blank string? I believe I will use str_replace but I am having a hard time doing this.

The quick brown fox jumped over [caption id="attachment_223" align="alignleft" width="900"] the head of the lazy dog.

Thanks in advance.

2
Contributors
2
Replies
3
Views
4 Years
Discussion Span
Last Post by jamojo
0

You'll need a regex for that. Something like this:

$string = 'The quick brown fox jumped over [caption id="attachment_223" align="alignleft" width="900"] the head of the lazy dog.';
$newstring = preg_replace('/\[.*?\]/i', '', $string);
echo $newstring;
0

Thanks for the reply pritaeas. It worked. I need to start working on my regex.

Thank you again.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.