【发布时间】:2019-11-02 10:14:25
【问题描述】:
这是来自数据库“fishPrice/1572268723Career Portal.pdf”的示例 url 我只想打印文件名“Career Portal” 最好的方法是什么?
我尝试过使用preg_match,但出现“未定义的偏移错误”
$fishPrice['price'] 包含网址
<?php
if(!empty($fishPrices))
{
foreach ($fishPrices as $fishPrice)
{
$date = strtotime($fishPrice['Date']);
$url = $fishPrice['price'];
$pattern = "[0-9]/";
preg_match('[0-9]', $url, $matches);
$price = $matches[1];
?>
<div class="">
<div class="col-lg-6 col-lg-offset-0 col-md-8 col-md-offset-2 col-sm-12">
<div class="container-outer">
<div class="container-inner ">
<div class="images-left">
<img src="http://via.placeholder.com/270x270" alt="girl-heart">
</div>
<div class="text-cont-right">
<div class="images-text">
<h3><a href="features-ecology.html"><?= date('M j Y', $date)?></a></h3>
<p><?= $price ?></p>
</div>
<div class="buttons">
<a href="admin/<?=$fishPrice['price']?>" class="green-btn green-btn-news">Read More</a>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
【问题讨论】:
-
取决于 url 的结构。它总是在正确名称之前有数字吗?您的印刷姓名是否也包含数字?
-
不,我们不会在打印出来的名字上加上数字。
标签: php regex parsing preg-match