![]() |
Duplicate " characters when creating links with preg_replace()
So, the goal here is for a script to turn a ten-digit phone number into a hyperlink, as follows.
Phone number 1234567890becomes <a href="tel:1-123-456-7890">(123) 456-7890</a>Testing out just the regex would imply that the following find/replace should work: Find: (\d{3})(\d{3})(\d{4})Replace: <a href="tel:1-$1-$2-$3">($1) $2-$3</a>However, if $val=1234567890, the following function: $val=preg_replace('/(\d{3})(\d{3})(\d{4})/','<a href="tel:1-$1-$2-$3">($1) $2-$3</a>',$val);Gives the following result: <a href=""tel:1-123-456-7890"">(123) 456-7890</a>Basically, every " in the $replacement string gets doubled. Any bright ideas on ways around this? |
| All times are GMT +1. The time now is 06:13 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.