-1

Hello what i am trying to do is find a word in text that starts with "pb" and make it a url

$message = 'test 123 message pb100000 message'

get the word pb100000 make it a hyperlink to www.google.com/search=pb100000 in html

What i have doen so far

echo preg_replace('/\bpd\S*gr/i', 
                  '<a href="https://www.google.com/search?br=${1}">Test</a>', 
                  'test 123 message pd100000gr message');

that makes an hyperlink under Test word, how can i make pd100000gr a hyperlink instead?

VlP3R
  • 11
  • 5

1 Answers1

0

With using anubhava solution in comments you can use like below in php.

echo preg_replace('/\b(pb\d+)/', 'www.google.com/search=${1}', 'test 123 message pb100000 message');
Abhishek Gurjar
  • 7,152
  • 9
  • 35
  • 40