derboehm 0 Posted March 23, 2006 Share Posted March 23, 2006 while(preg_match('#\[url\](.*?)\[/url]#si', $text, $matches)) { $t1 = (string) $matches[1]; if (strlen($t1) > 58) { $t2 = substr($t1, 0, 40)."...".substr($t1, -15); } else { $t2 = $t1; } $text = preg_replace('#\[url\](.*?)\[/url]#si',''.$t2.'',$text); } leider ist, wenn man zwei urls einträgt eine verschluckt und es wird nur eine angezeigt... evtl. weiß ja einer von euch einen rat... Quote Link to post Share on other sites
Powie 1 Posted March 24, 2006 Share Posted March 24, 2006 müsste da nicht preg_match_all helfen ? Quote Link to post Share on other sites
derboehm 0 Posted March 24, 2006 Author Share Posted March 24, 2006 fein, danke für den tipp preg_match_all('#\[url\](.*?)\[/url]#si', $text, $matches); for ($i=0; $i 58) { $t2 = substr($t1, 0, 40)."...".substr($t1, -15); } else { $t2 = $t1; } $text = preg_replace('#\[url\]'.$t1.'\[/url]#si',''.$t2.'',$text); } so bei allen links funktioniert es bis auf links wo ein '&' (kaufmännisches und) drin is da ich irgendwo vorher es umwandel zu '&' wie kann ich das rückgängig machen.. hab schon htmlspecialchars-decode ausprobiert... ging aber net Quote Link to post Share on other sites
Guest Posted March 24, 2006 Share Posted March 24, 2006 str_replace('&','&',$string); ? Quote Link to post Share on other sites
derboehm 0 Posted March 24, 2006 Author Share Posted March 24, 2006 hmm irgendwie kanns daran nicht liegen... geht auch damit nicht... hmmmm Quote Link to post Share on other sites
derboehm 0 Posted March 24, 2006 Author Share Posted March 24, 2006 ok so wie es aussieht liegt es am '?' Quote Link to post Share on other sites
derboehm 0 Posted March 24, 2006 Author Share Posted March 24, 2006 hinbekommen also wer den hack nutzen will, muss dann '#\[url\](.*?)\[/url]#si', und '\1', bei $search & $replace auskommentieren und das unter die array einfügen preg_match_all('#\[url\](.*?)\[/url]#si', $text, $matches); for ($i=0; $i 58) { $t2 = substr($t1, 0, 40)."...".substr($t1, -15); } else { $t2 = $t1; } $text = str_replace($matches[0][$i],''.$t2.'',$text); } Quote Link to post Share on other sites
mahe 0 Posted March 24, 2006 Share Posted March 24, 2006 Das geht mit einem preg_replace() und einer selbstgeschriebenen Funktion auch Ist vlt. effizienter da die Schleife dann wegfällt. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.