Jai
Jai

Reputation: 2204

How can i use php's preg_replace with a simple string and wildcards?

If i have the string [link="*"] where * is a wildcard how could i then use php to replace the string with <a href="*"> where * is the same value as before?

Is preg_replace the best way to do this?

Thanks, any help appreciated!

Upvotes: 5

Views: 6320

Answers (2)

genesis
genesis

Reputation: 50976

preg_replace('~\[link="(.*?)"\]~', '<a href="$1">', $text);

Upvotes: 7

Shef
Shef

Reputation: 45589

$link = '[link="http://www.google.com/"]';
$link = preg_replace('/\[link="(.*)"\]/', '<a href="$1">', $link);

Upvotes: 3

Related Questions