Avatar billede domaz.dk Novice
26. januar 2006 - 18:26 Der er 2 kommentarer og
1 løsning

preg_replace fejlfinding

nogle der kan se hva jeg gør forkert her...? den burde lave et www. url om til et link bortset fra hvis der f.eks. er http:// foran

$a_string = preg_replace("/(\s|tp\:|\(|\[|\&gt;)(www\.)([a-z0-9~#%@&:;=!',_æøå\(\)\?\/\.\-\+\[\]\|\*\$\^\{\}]+)/i", '\\1<a href="http://\\2\\3" target="_blank">\\2\\3</a>', $a_string);
Avatar billede domaz.dk Novice
26. januar 2006 - 20:16 #1
fandt en løsning!
Avatar billede well_r Nybegynder
26. januar 2006 - 23:17 #2
skriv den evt. op så andre kan se?
Avatar billede domaz.dk Novice
26. januar 2006 - 23:54 #3
<?php
/*############################################################
String Converter 0.46
--------------------------------------------------------------
This is a simpel text string converter...

$a_string
Your text variabel have to go here.

$a_url_target
Select between the different url target types. (e.g. '_blank', '_self' or '_top')
Default: '_blank'

$a_url_length
The maks length a URL is visible. ('...' will finish the url if to long)

Made by Thomas Hansen
http://domaz.dk - find more scripts!
############################################################*/
function a_string_out($a_string, $a_url_target = "_blank", $a_url_length = "25") {
    $a_string = " ".$a_string;
    $url_ins_str = ' target="'.$a_url_target.'"';
   
    $a_string = str_replace("&", '&amp;', $a_string);
    $a_string = str_replace("<", '&lt;', $a_string);
    $a_string = str_replace(">", '&gt;', $a_string);
    $a_string = str_replace("\n", '<br>\n', $a_string);

    $a_string = preg_replace("/\[([biu])\]/i", '<$1>', $a_string); // convert , or to html-tags
    $a_string = preg_replace("/\[\/([biu])\]/i", '</$1>', $a_string); // convert
, or to html-tags
   
    // make LINK's automatically
    $a_string = preg_replace_callback("/(ftp|http|https|telnet|news|nntp|file|irc):\/\/([a-z0-9~#&:;=!',_æøå\(\)\?\/\.\-\+\[\]\|\*\$\%\^\{\}]+)/i", create_function('$matches','if( strlen($matches[2]) > '.$a_url_length.' ) $name = substr($matches[2],0,'.$a_url_length.') . "..."; else $name = $matches[2]; return "<a".$url_ins_str." href=\"{$matches[1]}://{$matches[2]}\">$name</a>";'),$a_string);
    $a_string = preg_replace_callback ("/( www\.)([a-z0-9~#&:;=!',_æøå\(\)\?\/\.\-\+\[\]\|\*\$\%\^\{\}]+)/i", create_function('$matches','if( strlen($matches[2]) > '.$a_url_length.' ) $name = substr($matches[1], 1).substr($matches[2],0,'.$a_url_length.') . "..."; else $name = substr($matches[1], 1).$matches[2]; return " <a".$url_ins_str." href=\"http://".substr($matches[1], 1).$matches[2]."\">$name</a>";'), $a_string);
    $a_string = preg_replace_callback ("/( ftp\.)([a-z0-9~#&:;=!',_æøå\(\)\?\/\.\-\+\[\]\|\*\$\%\^\{\}]+)/i", create_function('$matches','if( strlen($matches[2]) > '.$a_url_length.' ) $name = substr($matches[1], 1).substr($matches[2],0,'.$a_url_length.') . "..."; else $name = substr($matches[1], 1).$matches[2]; return " <a".$url_ins_str." href=\"ftp://".substr($matches[1], 1).$matches[2]."\">$name</a>";'), $a_string);

    // make EMAIL's automatically
    $a_string = preg_replace("/[\\d\\w\\.\\-_]+@[\\d\\w\\-_\\.]+?\\.[\\w]{2,3}(\\.[\\w]{2,3})?/i", '<a href="mailto:\\0">\\0</a>', $a_string);
   
    return substr($a_string, 1);
}
?>
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Vi tilbyder markedets bedste kurser inden for webudvikling

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester

Seneste spørgsmål Seneste aktivitet
I går 21:00 Libre Office Impress Af Frank i Andre styresystemer
I går 11:47 VB script Af Jenshentze i Word
I går 11:21 Popup ved opstart Af mort1 i Windows
04/0918:50 Slet lokal konto Af ErikHg i Windows
04/0916:05 Ændre tal i en celle Af xvid i Excel