试图在页面上找到链接.
我的正则表达式是:
/<a\s[^>]*href=(\"\'??)([^\"\' >]*?)[^>]*>(.*)<\/a>/
Run Code Online (Sandbox Code Playgroud)
但似乎失败了
<a title="this" href="that">what?</a>
Run Code Online (Sandbox Code Playgroud)
我如何更改我的正则表达式来处理未首先放在标签中的href?
我想只选择一个名为.date的类
出于某种原因,我不能让这个工作.如果有人知道我的代码有什么问题,我将不胜感激.
@$doc = new DOMDocument();
@$doc->loadHTML($html);
$xml = simplexml_import_dom($doc); // just to make xpath more simple
$images = $xml->xpath('//[@class="date"]');
foreach ($images as $img)
{
echo $img." ";
}
Run Code Online (Sandbox Code Playgroud) 使用PHP Xpath尝试快速拉取html页面中的某些链接.
以下内容将在mypage.html上找到所有href链接:
$nodes = $x->query("//a[@href]");
以下将找到描述与我的针匹配的所有href链接:
$nodes = $x->query("//a[contains(@href,'click me')]");
我想要实现的是匹配href本身,更具体的发现包含某些参数的url.这可能在Xpath查询中,还是我应该开始操作第一个Xpath查询的输出?
我有一个XML文件
<?xml version="1.0" encoding="UTF-8"?>
<xml>
<events date="12/12/2010">
<event>
<title>JqueryEvent</title>
<description>
easily
</description>
</event>
</events>
<events date="14/12/2011">
<event>
<title>automatically onBlur</title>
<description>
when a date is selected. For an inline calendar, simply attach the datepicker to a div or span.
</description>
</event>
</events>
</xml>
Run Code Online (Sandbox Code Playgroud)
我正在使用此Xpath来选择节点
$xml = simplexml_load_file($file);
$nodes = $xml->xpath('//xml/events');
Run Code Online (Sandbox Code Playgroud)
它将选择所有节点.我想根据日期选择节点.
我需要知道特定节点中是否存在特定字符串.例如,我需要知道HTML DOM的第3段中是否存在"快速棕色狐狸".我正在使用PHP的DOMXPath.有什么建议?
我正在使用以下函数将_blank添加到我网站上的所有链接.
function targetBlank($text) {
$return = str_replace('<a', '<a target="_blank"', $text);
return $return;
}
Run Code Online (Sandbox Code Playgroud)
我正在寻找一种解决方案,只在外部链接(不在我的域上)而不是所有链接上应用此功能.
您好我的Regex代码有问题,我用它来使用PHP从HTML标签中获取值.我有以下字符串可能:
<span class="down last_position">xyz</span>
<span class="up last_position">xyz</span>
<span class="last_position new">xyz</span>
Run Code Online (Sandbox Code Playgroud)
我有以下preg_match命令:
preg_match('#<span class="last_position.*?">(.+)</span>#', $string, $matches);
Run Code Online (Sandbox Code Playgroud)
这几乎只涉及案例#3.所以我想知道在last_position前面需要添加什么才能使所有情况都成为可能..?
非常感谢..
编辑:对于所有想知道要匹配什么值的人:"xyz"