【发布时间】:2014-08-13 09:07:29
【问题描述】:
我需要用元音 i 替换某些先前选择的链接上出现的所有元音 (a,e,i,o,u)。这是某种内部笑话(网站翻译应用程序)。到目前为止,我想出了这个:
<?php
if ($_GET['sajt']!=NULL)
{
$url = str_replace('&', '&', $_GET['sajt']);
$ch = curl_init();
// Set url and other options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// Get the page contents
$html = curl_exec($ch);
// close curl resource to free up system resources
curl_close($ch);
$vowels = array("a", "e", "i", "o", "u");
$onlyconsonants = str_replace($vowels, "i", $html);
$vowels = array("A", "E", "I", "O", "U");
$onlyconsonants = str_replace($vowels, "I", $onlyconsonants);
echo $onlyconsonants;
}
?>
但是,在我这样做之后,str_replace 也会更改 html 标签,因为整个 html 页面都存储在同一个字符串中(例如 head to hiid)。我进行了搜索,但我无法找到正确执行此操作的方法,因为它需要某种 html 解析然后将它们合并在一起
【问题讨论】:
标签: php html curl replace tags