我使用简单的php dom解析器来获取表格td内容,我将其输出为明文,并且如下所示:
<p> Graphic Artist / Designer<br />
$23,755 – $55,335 <br /> Sales Associate<br />
$15,577 – $56,290 <br /> Film / Video Editor<br />
$24,184 – $94,493 </p>
我想做的是采取上述措施,并将其转化为:
<a href="/graphic-artist-designer">Graphic Artist / Designer</a>
$23,755 – $55,335 <br />
<a href="/sales-associate">Sales Associate</a><br />
$15,577 – $56,290 <br />
<a href="/film-video-editor">Film / Video Editor</a><br />
$24,184 – $94,493 <br />
因此,您可以看到即时取下作业名称,降低所有内容的大小,并用短划线替换空格和斜线以用作URL。
我该怎么做?
答案 0 :(得分:1)
您可以将其转换为小写,然后以这种方式消除非单词字符:
$slug = preg_replace('/[^a-z]+/', '-', strtolower($name));
如果您无法将其整合到解决方案中,请参阅http://www.php.net/manual/en/function.preg-replace-callback.php