urlencode dentro de preg_replace, ¿es posible?

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?

preguntado el 28 de mayo de 14 a las 12:05

Mira esto preg_replace_callback -

@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. -

Where do you want to place urlencode() ¿función? -

@RahilWazir after the away?to= -

0 Respuestas

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.