Zum Inhalt springen

Empfohlene Beiträge

Geschrieben

hi...

wie kann ich aus einem beliebigen text, zB gbook eintragt (also text aus db) alle urls heraussuchen und dann auch als link wiedergeben?

hat jeder schonmal gesehen... hier gehts ja auch automatisch denk ich

www.google.de

Geschrieben

Ich hab irgendwo im Internet mal folgendes gefunden.


//-----------------------------------------------------------------------------
//Funktion um URL und E-Mail Adressen als Link umzuwandeln
//-----------------------------------------------------------------------------
function make_clickable($text)
{

// pad it with a space so we can match things at the start of the 1st line.
$ret = ' ' . $text;

// matches an "xxxx://yyyy" URL at the start of a line, or after a space.
// xxxx can only be alpha characters.
// yyyy is anything up to the first space, newline, comma, double quote or <
$ret = preg_replace("#(^|[\n ])([\w]+?://.*?[^ \"\n\r\t<]*)#is", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $ret);

// matches a "www|ftp.xxxx.yyyy[/zzzz]" kinda lazy URL thing
// Must contain at least 2 dots. xxxx contains either alphanum, or "-"
// zzzz is optional.. will contain everything up to the first space, newline,
// comma, double quote or <.
$ret = preg_replace("#(^|[\n ])((www|ftp)\.[\w\-]+\.[\w\-.\~]+(?:/[^ \"\t\n\r<]*)?)#is", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $ret);

// matches an email@domain type address at the start of a line, or after a space.
// Note: Only the followed chars are valid; alphanums, "-", "_" and or ".".
$ret = preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $ret);

// Remove our padding..
$ret = substr($ret, 1);

return($ret);
}
[/php]

Frank

Geschrieben

ähnlich der obenstehenden funktion...

1) entsprechende seite als string einlesen

2) mit hilfe von regulären ausdrücken die enthaltenen links ermitteln

3) mit php die links ausgeben

für alle schritte findest du informationen der notwendigen funktionen im php-handbuch und eine einführung in die welt der regulären ausdrücke unter http://www.it-development.de/tutorials/read/10/1/.

das sollte dir bei deinem vorhaben erstmal weiterhelfen.

Erstelle ein Benutzerkonto oder melde Dich an, um zu kommentieren

Du musst ein Benutzerkonto haben, um einen Kommentar verfassen zu können

Benutzerkonto erstellen

Neues Benutzerkonto für unsere Community erstellen. Es ist einfach!

Neues Benutzerkonto erstellen

Anmelden

Du hast bereits ein Benutzerkonto? Melde Dich hier an.

Jetzt anmelden

Fachinformatiker.de, 2024 by SE Internet Services

fidelogo_small.png

Schicke uns eine Nachricht!

Fachinformatiker.de ist die größte IT-Community
rund um Ausbildung, Job, Weiterbildung für IT-Fachkräfte.

Fachinformatiker.de App

Download on the App Store
Get it on Google Play

Kontakt

Hier werben?
Oder sende eine E-Mail an

Social media u. feeds

Jobboard für Fachinformatiker und IT-Fachkräfte

×
×
  • Neu erstellen...