Reputation: 727
I'm looking for a way to str_replace variable content. So that I can change this:
...and in week 1 we saw that...
into this:
...and in <a href="/?w=1">week 1</a> we saw that...
I know how str_replace works and I could solve it by just running a hundred different queries, each with another week. But what I want is a query that looks for this:
'week ' + X
So a query that finds every string 'week '
that is followed by a number. Can anyone help me solve this? :)
Tx!
Upvotes: 0
Views: 93
Reputation: 21422
Instead of str_replace
you can use preg_replace
like as
preg_replace('/(week\s?(\d+))/',"<a href='/?w=$2'>$1</a>",$your_string);
Upvotes: 2