php – Regular Expression Schnipsel – Links aus -Tags

closeThis post was published more than three months ago. Please note that the information offered here may no longer be current and valid. Therefore, please inform yourself about this topic elsewhere. If there is any new information, you can also send me a comment. Thank you so much!

Habe zu dem Thema (“Reguläre Ausdrücke”) bereits ausführlicher geschrieben -> <- daher folgt hier einfach ein Beispiel, welches man sicherlich noch optimieren kann … :)

$lall =' lall lall123
<a style="gfsedfd;" href="">test
<a style="gfsedfd;" href="test2.php" target="_blank>test</a> dsadsa
<a style="gfsedfd;" href="" target="_blank>test</a>

$lall = str_ireplace("\r", '', $lall);
$lall = str_ireplace("\n", '', $lall);
$lall = str_ireplace("\t", '', $lall);
preg_match_all('/<a [^>].*href="(.*)".*>/i', $lall, $lall_new);
$allLinks = explode("</a>", $lall_new[0][0]);
foreach ($allLinks as $key => $val) {
  $val = trim($val);
  if ($val != '') {
    $data =preg_replace('/.*<a [^>].*href\s*=\s*(["\'])(.*?)\1.*>.*/i',"$2",$val);
    echo $data . "\n";
php testtest.php

Published by


Lars Moelleken | Ich bin root, ich darf das!

%d bloggers like this: