Reputation: 2123
I cant get the regex to identify the date from a string and remove it with string replace:
<?php
$string = "keywords=2012+some+words";
echo $string ."<br />";
$new_string = str_replace("keywords=/^([0-9]{4})$/","keywords=",$string);
echo $new_string ;
?>
I have read this post Regex to remove year from a string PHP
and just cant get it to work
Upvotes: 2
Views: 1653
Reputation: 219938
To use a regex, use preg_replace
, and pass it an actual regex:
$new_string = preg_replace("/^keywords=\d{4}/", "keywords=", $string);
See it here in action: http://codepad.viper-7.com/dxwxvG
Upvotes: 3