私は検索して正しい答えを得られないようです。私はこのような特定のHTML文字列内のすべてのリンクを交換したい:htmlリンクタグをテキストの説明に置き換えます。
... <a href="link.php">Description Here</a> ...
to:
Description Here: link.php
これは非HTML形式の電子メールクライアントがリンクを参照し、コピーしてブラウザに貼り付けできる能力を持つことができるようです。
私は検索して正しい答えを得られないようです。私はこのような特定のHTML文字列内のすべてのリンクを交換したい:htmlリンクタグをテキストの説明に置き換えます。
... <a href="link.php">Description Here</a> ...
to:
Description Here: link.php
これは非HTML形式の電子メールクライアントがリンクを参照し、コピーしてブラウザに貼り付けできる能力を持つことができるようです。
あなたはこのような何かを行うことができます:
$text = '<a href="link.php">Description Here</a>';
$replaced = preg_replace('/<a [^>]*href="(.*)"[^>]*>(.*)<\/a>/', '$2: $1', $text);
PCREがあなたを救う:
$text = '<a href="link.php">Description Here</a>';
echo preg_replace("/\<a.*href=\"(.*)\".*\>(.*)\<\/a\>/Usi",'$2: $1',$text);
echo preg_replace("/<a.*?href=\"(.*?)\".*?>(.*?)<\/a>/i", "$2: $1", $html);
を純粋なPHPで、あなたは可能性が一般的なhtmlファイルから:また
<?php
//an example html string
$dataStr = '<ul id="sub-menu">
<li class="parent item10"><a href="link1.php">Arts</a>
<ul>
<li class="item29">
<a href="link2.php">Arts Show</a></li>
<li class="item29">
<a href="link3.php">Another Arts Show</a></li>
</ul>
</li>
<li class="parent item15"><a href="link6.php">News</a>
<ul>
<li class="item18">
<a href="link7.php">News Show</a></li>
</ul>
</li>
</ul>';
$startIndex = strpos($dataStr, "<a", 0);
$endIndex = strpos($dataStr, "</a", $startIndex);
while (1==1){
if($startIndex == false || $endIndex == false){
break;
}
$currentLine = substr($dataStr,$startIndex,($endIndex-$startIndex)+4);
$linkStartIndex = strpos($currentLine, "href=", 0)+6;
$linkEndIndex = strpos($currentLine, '"', $linkStartIndex);
$currentLink = substr($currentLine,$linkStartIndex,$linkEndIndex-$linkStartIndex);
$descriptionStartIndex = strpos($currentLine, ">", $linkEndIndex)+1;
$descriptionEndIndex = strpos($currentLine, "<", $descriptionStartIndex);
$currentDescription = substr($currentLine,$descriptionStartIndex,$descriptionEndIndex-$descriptionStartIndex);
echo ($currentDescription.": ".$currentLink."\n");
$startIndex = strpos($dataStr, "<a", $endIndex+5);
$endIndex = strpos($dataStr, "</a", $startIndex);
}
?>
'Description HereDescription Here 'が動作します。 ng ...修飾子(U)ここではUngreedyが重要であり、複数行のリンクを許可し、(A)タグを許可します。 –