Reputation: 642
I have the following string stored in a variable (which is taken from a database)
$string = 'some simple text i need [link href="http://www.somelink.com/..."]some link i dont need here[/link] some simple text i need too.';
I'm trying to remove the following part from the string:
[link href="http://www.somelink.com/..."]some link i dont need here[/link]
This is the final output I wish to have:
some simple text i need some simple text i need too.
How can I accomplish this using PHP?
Upvotes: 1
Views: 114
Reputation: 68526
Use this regex ~\[link(.*?)\[\/link]~
<?php
$string = 'some simple text i need [link href="http://www.somelink.com/..."]some link i dont need here[/link] some simple text i need too.';
echo $str = preg_replace("~\[link(.*?)\[\/link]~","", $string);
OUTPUT :
some simple text i need some simple text i need too.
Upvotes: 3