 |
| Hinweise |
Willkommen im TP-Hilfe-Forum!Dies ist ein Forum zu den Themen Photoshop, Dreamweaver, Flash, Selbständigkeit und mehr, in dem Du Hilfe, Anleitung oder eine Lösung zu Deinen Problemen erhältst. Aktuell bist Du in unseren Foren als Gast mit reinen Leserechten unterwegs. Wenn Du Dich registrierst, kannst Du eigene Themen verfassen, deine Frage stellen und privat mit anderen TPlern kommunizieren. Weitere Foren werden zugänglich, und Du wirst – falls gewünscht – per Mail über neue Beiträge informiert. Die Registrierung ist schnell und kostenlos. Sollten bei der Registrierung Fragen auftauchen, reicht ein Klick in unsere Hilfe - Häufig gestellte Fragen oder eine kurze Mitteilung an das Support-Team. Viel Spaß bei Traum-Projekt.com |
12.09.2007, 11:47
|
#1
|
|
TP-Veteran
Registriert seit: Jun 2001
Ort: Wien
|
Email-/Internetadressen in links umwandeln
Hey,
ich suche eine PHP-Funktion die mir alle Email-/Internetadressen in einem Text in HTML-Links umwandelt.
Ich hab schon gegoogelt find aber bis jetzt leider nix passendes!
Könnt ihr mir bitte helfen!
Danke!
lg
Flow
__________________
Lesser known Programming Languages #13: SLOBOL
... Although many compilers allow you to take a coffee break while they compile, SLOBOL compilers allow you to travel to Bolivia to pick the coffee. Forty-three programmers are known to have died of boredom sitting at their terminals while waiting for a SLOBOL program to compile. Weary SLOBOL programmers often turn to a related (but infinitely faster) language, COCAINE.
|
|
|
12.09.2007, 12:10
|
#2
|
|
TP-Moderator
Registriert seit: Aug 2004
Ort: Kaiserslautern
|
Zitat:
Zitat von Flow09
Ich hab schon gegoogelt find aber bis jetzt leider nix passendes!
|
Das wundert mich etwas, weil wir Dir in diesem Thread das schon mal anhand deiner "PLZ" erklärt haben. Fertige Suchmuster für Email- und Web-Adressen findest Du tonnenweise unter dem Link den ich in diesem Thread geposted habe. Das Ersetzen-Prozedere ist das selbe wie bei den PLZ, nur das Suchmuster ist ein anderes.
__________________
#.Viele Grüße, Andreas
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
.
|
|
|
12.09.2007, 12:22
|
#3
|
|
TP-Veteran
Registriert seit: Jun 2001
Ort: Wien
|
Ja, auf php.net bin ich inzwischen auch schon auf brauchbares gestoßen!!
Genauer gesagt auf diese Funktion:
PHP-Code:
function replaceLink($text) {
$text = ereg_replace('[-a-z0-9!#$%&\'*+/=?^_`{|}~]+@([.]?[a-zA-Z0-9_/-])*','<a href="/newmessage/\\0/">\\0</a>',$text);
$text = ereg_replace('[a-zA-Z]+://(([.]?[a-zA-Z0-9_/-])*)','<a target="_blank" href="\\0">\\1</a>',$text);
$text = ereg_replace('(^| )(www([-]*[.]?[a-zA-Z0-9_/-?&%])*)',' <a target="_blank" href="http://\\2">\\2</a>',$text);
return $text;
}
Hierbei hab ich allerdings noch ein Problem wenn ich einen Text mit mehreren Links übergebe wird nur der erste Link umgewandelt und der Rest nicht mehr.
ereg_replace dürfte nach dem ersten match aufhören!?!?! 
__________________
Lesser known Programming Languages #13: SLOBOL
... Although many compilers allow you to take a coffee break while they compile, SLOBOL compilers allow you to travel to Bolivia to pick the coffee. Forty-three programmers are known to have died of boredom sitting at their terminals while waiting for a SLOBOL program to compile. Weary SLOBOL programmers often turn to a related (but infinitely faster) language, COCAINE.
|
|
|
17.09.2007, 10:43
|
#4
|
|
TP-Veteran
Registriert seit: Jun 2001
Ort: Wien
|
Also, wie schon gesagt, die Funktion die ich gefunden habe ist schön und gut! Allerdings hat sie einige Fehler:
1.) Bei Texten mit mehreren Links wird nur der erste Link umgewandelt und der Rest nicht!
2.) Bei Links mit GET Argumenten (wie z.B von youTube http://www.youtube.com/watch?v=lQNDHY6hu_o) funkt das auch nicht.
Kann mir bitte einer weiterhelfen, ich hab von reg exps ziemlich wenig Ahnung!
lg
Flow
__________________
Lesser known Programming Languages #13: SLOBOL
... Although many compilers allow you to take a coffee break while they compile, SLOBOL compilers allow you to travel to Bolivia to pick the coffee. Forty-three programmers are known to have died of boredom sitting at their terminals while waiting for a SLOBOL program to compile. Weary SLOBOL programmers often turn to a related (but infinitely faster) language, COCAINE.
|
|
|
23.10.2007, 11:07
|
#5
|
|
TP-Veteran
Registriert seit: Jun 2001
Ort: Wien
|
So, inzwischen hab ich die Lösung gefunden:
PHP-Code:
$text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_+.~#?&//=]+)',
'<a href="\1" target=_blank>\1</a>', $text);
$text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_+.~#?&//=]+)',
'\1<a href="http://\2" target=_blank>\2</a>', $text);
Mir fehlt jetzt nur noch ein kleines Stück! Ich möchte alle Links nur mit der Domain anzeigen: Sprich der Link http://www.domin.com/var?x=blablabla soll nur als "www.domain.com" angezeigt werden.
Ich bekomm das aber nicht hin, ich brauche bitte eure Hilfe!!
lg
Flow
__________________
Lesser known Programming Languages #13: SLOBOL
... Although many compilers allow you to take a coffee break while they compile, SLOBOL compilers allow you to travel to Bolivia to pick the coffee. Forty-three programmers are known to have died of boredom sitting at their terminals while waiting for a SLOBOL program to compile. Weary SLOBOL programmers often turn to a related (but infinitely faster) language, COCAINE.
|
|
|
23.10.2007, 11:18
|
#6
|
|
TP-Moderator
Registriert seit: Aug 2004
Ort: Kaiserslautern
|
Zitat:
Zitat von Flow09
Mir fehlt jetzt nur noch ein kleines Stück! Ich möchte alle Links nur mit der Domain anzeigen: Sprich der Link http://www.domin.com/var?x=blablabla soll nur als "www.domain.com" angezeigt werden.
|
Mal diese quick & dirty Lösung als Ansatz
PHP-Code:
<?php
$url = "http://www.domin.com/var?x=blablabla";
preg_match( "#http://(.*)/(.*)#", $url, $treffer );
echo $treffer[1];
?>
__________________
#.Viele Grüße, Andreas
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
.
|
|
|
23.10.2007, 11:33
|
#7
|
|
TP-Veteran
Registriert seit: Jun 2001
Ort: Wien
|
Danke für die Hilfe, aber das is nicht so ganz was ich Suche. Das ganze sollte in den schon vorhandenen Code eingebaut werden.
Ausserdem sollte es bei all diesen Fällen hier funktionieren:
http://www.domain.com/asdjkfhas
http://www.domain.com
http://domain.com
http://domain.com/jnsjlhsxcj
www.domain.com
www.domain.com/haskjdhasjkhdk
Aber trotzdem danke, vielleicht fällt mir da ja noch was ein!
lg
Flow
__________________
Lesser known Programming Languages #13: SLOBOL
... Although many compilers allow you to take a coffee break while they compile, SLOBOL compilers allow you to travel to Bolivia to pick the coffee. Forty-three programmers are known to have died of boredom sitting at their terminals while waiting for a SLOBOL program to compile. Weary SLOBOL programmers often turn to a related (but infinitely faster) language, COCAINE.
|
|
|
23.10.2007, 11:38
|
#8
|
|
TP-Moderator
Registriert seit: Aug 2004
Ort: Kaiserslautern
|
Deswegen sagte ich ja auch "Ansatz"!
Kombiniere eben mal dein funktionierendes Suchmuster mit dem von mir geposteten preg_match und schon hast Du was funktionierendes. Mein Schnipsel sollte Dir lediglich zeigen wie man an das ausgefilterte Ergebnis kommt, mehr nicht!
EDIT
BTW, wenn die URL bereits vorliegt könntest Du es dir auch leicht machen und parse_url benutzen.
__________________
#.Viele Grüße, Andreas
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
.
|
|
|
24.10.2007, 22:52
|
#9
|
|
TP-Specialist
Registriert seit: Jan 2004
Ort: Münster-Hiltrup
|
Also, ich mache es beim auslesen von Emailadressen so aus einer Datenbank zum Beispiel so:
Natürlich geht das auch mit Urls
PHP-Code:
<a href="mailto:<?PHP echo $email."?subject=Antwort an $kontaktvorname $kontaktnachname aus Tourenanfrage vom $kontakteintragsdatum $kontaktinfo.";?>" class="linkweiss2"><?PHP echo $email;?></a>
Geändert von MichaelM (24.10.2007 um 22:58 Uhr).
|
|
|
30.10.2007, 18:43
|
#10
|
|
TP-Veteran
Registriert seit: Jun 2001
Ort: Wien
|
So!
Jetzt hab ich mir mal das hier zusammegestückelt!
PHP-Code:
preg_replace("#(^|[\n ])(([\w]+?://[\w\#$%&~.\-;:=,?@\[\]+]*)(/[\w\#$%&~/.\-;:=,?@\[\]+]*))#si", "\\1<a href=\"\\2\" target=\"_blank\">\\3</a>", $ret);
Bis auf eine Kleinigkeit erledigt das auch seine arbeit sehr gut. Folgendes Problem hab ich nur noch, das regex funkt bei url strings wie http://www.domain.com/blabla und http://www.domain.com/
Leider kommt es bei http://www.domain.com (also ohne / am Ende) zu Problemen. Der String wird nicht gefunden ohne ein Slash am Ende. Ich hab jetzt schon einiges ausprobiert, finde die Lösung aber nicht. Ich brauche also bitte nochmal eure Hilfe.
lg
Flow
__________________
Lesser known Programming Languages #13: SLOBOL
... Although many compilers allow you to take a coffee break while they compile, SLOBOL compilers allow you to travel to Bolivia to pick the coffee. Forty-three programmers are known to have died of boredom sitting at their terminals while waiting for a SLOBOL program to compile. Weary SLOBOL programmers often turn to a related (but infinitely faster) language, COCAINE.
|
|
|
31.10.2007, 10:07
|
#11
|
|
TP-Veteran
Registriert seit: Jun 2001
Ort: Wien
|
Hab die Lösung:
PHP-Code:
preg_replace("#(^|[\n ])(([\w]+?://[\w\#$%&~.\-;:=,?@\[\]+]*)(/[\w\#$%&~/.\-;:=,?@\[\]+]*)?)#is", "\\1<a href=\"\\2\" target=\"_blank\">\\3</a>", $text);
preg_replace("#(^|[\n ])(((www|ftp)\.[\w\#$%&~.\-;:=,?@\[\]+]*)(/[\w\#$%&~/.\-;:=,?@\[\]+]*)?)#is", "\\1<a href=\"http://\\2\" target=\"_blank\">\\3</a>", $text);
__________________
Lesser known Programming Languages #13: SLOBOL
... Although many compilers allow you to take a coffee break while they compile, SLOBOL compilers allow you to travel to Bolivia to pick the coffee. Forty-three programmers are known to have died of boredom sitting at their terminals while waiting for a SLOBOL program to compile. Weary SLOBOL programmers often turn to a related (but infinitely faster) language, COCAINE.
|
|
|
|
Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1)
|
|
|
| Themen-Optionen |
Thema durchsuchen |
|
|
|
| Thema bewerten |
|
|
Forumregeln
|
Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.
HTML-Code ist aus.
|
|
|
Alle Zeitangaben in WEZ +2. Es ist jetzt 20:19 Uhr.
|
 |