urlencode dentro de preg_replace, ¿es posible?
Frecuentes
Visto 206 equipos
0
Using following code to convert URLs within a text into real HTML links:
$string = preg_replace("!(http|https|ftp|ftps)://([.]?[&;%#:=a-zA-Z0-9_/?-])*!", "<a href=\"away?to=\\0\">\\0</a>", $string);
$string = preg_replace("!(^| |\n)(www([.]?[&;%#:=a-zA-Z0-9_/?-])+)!", "\\1<a href=\"away?to=www.\\2\">\\2</a>", $string);
Now there is a problem with URLs containing the # symbol (and perhaps other special chars too) and I would need the urlencode()
function somehow within this preg_replace()
función.
¿Alguna idea?
0 Respuestas
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas php preg-replace urlencode urldecode preg-replace-callback or haz tu propia pregunta.
Mira esto
preg_replace_callback
- Daan@Daan: Do you have an example for me regarding my code? Never worked with preg_replace_callback and haven't understood yet what I've read about how to use it with my code. - lickmycode
Where do you want to place
urlencode()
¿función? - Rahil Wazir@RahilWazir after the
away?to=
- lickmycode