triplexim32 Posted November 17, 2009 at 06:54 PM Report Share #296687 Posted November 17, 2009 at 06:54 PM Quero fazer replace de links, tipo se eu tiver isto: www.google.pt ou http:\\www.google.pt ficar isto [ url]www.google.pt[/url] mas tenho que ter em conta que se tiver isto [ img]www.google.pt[ /img] Aqui o replace não pode ser feito. Alguma sugestão? < Link to comment Share on other sites More sharing options...
yoda Posted November 17, 2009 at 06:56 PM Report Share #296689 Posted November 17, 2009 at 06:56 PM Isso é conseguido com regex, se for PHP. before you post, what have you tried? - http://filipematias.info sense, purpose, direction Link to comment Share on other sites More sharing options...
scorch Posted November 17, 2009 at 06:59 PM Report Share #296694 Posted November 17, 2009 at 06:59 PM Tenta isto: preg_replace('\b(https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|]', '[url]\0[/url]', $text); PS: Não respondo a perguntas por mensagem que podem ser respondidas no fórum. Link to comment Share on other sites More sharing options...
yoda Posted November 17, 2009 at 07:00 PM Report Share #296696 Posted November 17, 2009 at 07:00 PM @scorch, isso não valida se começa por ou não. before you post, what have you tried? - http://filipematias.info sense, purpose, direction Link to comment Share on other sites More sharing options...
triplexim32 Posted November 18, 2009 at 11:33 PM Author Report Share #296842 Posted November 18, 2009 at 11:33 PM Tenta isto: preg_replace('\b(https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|]', '[url]\0[/url]', $text); tenho assim: $message = preg_replace('\b(https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|]', '\0', $message); ta a dar este erro: Warning: preg_replace() [function.preg-replace]: Delimiter must not be alphanumeric or backslash in /home/host/public_html/include/functions.inc.php on line 595 BTW o que faz o \b? < Link to comment Share on other sites More sharing options...
scorch Posted November 19, 2009 at 09:46 AM Report Share #296866 Posted November 19, 2009 at 09:46 AM Tenta isto. $message = preg_replace('\b(https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|]', '[url]\0[/url]', $message); PS: Não respondo a perguntas por mensagem que podem ser respondidas no fórum. Link to comment Share on other sites More sharing options...
triplexim32 Posted November 19, 2009 at 06:50 PM Author Report Share #296918 Posted November 19, 2009 at 06:50 PM Tenta isto. $message = preg_replace('\b(https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|]', '[url]\0[/url]', $message); Continua a dar o mesmo erro e é so nessa linha 😉 < Link to comment Share on other sites More sharing options...
yoda Posted November 20, 2009 at 09:05 AM Report Share #296977 Posted November 20, 2009 at 09:05 AM Expressões regulares são uma coisa complicada de aprender, mas depois de se aprender e "masterizar" são algo bastante útil. Sugiro que leias sobre os parametros disponíveis, e que procures exemplos práticos para cada caso, de modo a aprenderes mais sobre o assunto. before you post, what have you tried? - http://filipematias.info sense, purpose, direction Link to comment Share on other sites More sharing options...
triplexim32 Posted November 21, 2009 at 01:05 AM Author Report Share #297068 Posted November 21, 2009 at 01:05 AM Expressões regulares são uma coisa complicada de aprender, mas depois de se aprender e "masterizar" são algo bastante útil. Sugiro que leias sobre os parametros disponíveis, e que procures exemplos práticos para cada caso, de modo a aprenderes mais sobre o assunto. Pois eu ja tive a ver algumas coisas, mas há tantas maneiras de fazer uma cena que eu fico confuso. O que me dava mais jeito neste momento era fazer isto: Não pode existir o caracter "]" (http:\\www OU www).site.com Mas não consigo fazer o que esta a vermelho :S < Link to comment Share on other sites More sharing options...
infopc Posted November 24, 2009 at 09:27 AM Report Share #297377 Posted November 24, 2009 at 09:27 AM os parentesis rectos são caracteres especiais em regex, como tal tens que os escapar. ex: "\[" VALIDO "[" INVALIDO O que não tem solução, solucionado esta... Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now