Reputation: 209
Trying to use preg_replace to find words with @ in them and replace the whole word with nothing.
<?php
$text = "This is a text @removethis little more text";
$textreplaced = preg_replace('/@*. /', '', $text);
echo $captions;
Should output: This is a text little more text
Been trying to google on special charc and such but am lost.
Upvotes: 0
Views: 71
Reputation: 92
I believe you are only finding the '@' to begin with, but if you find the whole string inside use \b
around the regex so your final regex should be something like /(@).{2,}?\b/
.
The ? mark is important because regexes are greedy and grab as many letters as posible
Just a tip visit a tester like regexpal
Upvotes: 1
Reputation: 36924
Use \w
:
$textreplaced = preg_replace('/@[\w]+ /', '', $text);
echo $textreplaced;
Upvotes: 1