php - 如何在php中删除前几个字母并打印最后一个标题
问题描述
我有永久链接和页面标题。我需要删除唯一的永久链接并使用 PHP 打印标题。这是代码:
$string = "http://example.com/blog/PageTitle"
从这里删除http://example.com/blog/
并仅打印PageTitle
我尝试过这个:
$string = 'http://example.com/blog/PageTitle';
$remove_text = 'http://example.com/blog/'
$count = strlen($remove_text)
echo substr($string, $count);
注意:我的$string
和pageTitle
是可变的http://example.com/about/PageTitle
,http://example.com/contact/PageTitle2
等等。
解决方案
试试这个
$string = strrev($string);
$str_arr = explode ("/", $string);
$pageTitle = $str_arr[0];
$pageTitle = strrev($pageTitle);
echo $pageTitle;
这应该有效。
推荐阅读
- hibernate - 获取 [-] 错误无法将数据库状态与会话同步:org.hibernate.event.def.AbstractFlushingEventListener-(277)
- html - Django中表单输入字段的CSS样式
- r - 根据 R 中的多列和条目顺序删除行
- openstreetmap - 锇 - 将输出标头添加到 PBF
- jsp - 具有自定义对象的地图上的 JSTL foreach
- namespaces - x 不是命名空间的成员
- c# - 使用 EPPlus 将文本框添加到图表
- python - 使用请求 html 抓取时空格变成问号
- python - Pyodbc - “服务器不存在或访问被拒绝。”
- javascript - 使用 Webpack 4 对代码库进行重复数据删除