简体   繁体   English

从PHP中的URL获取文本

[英]Get Text From URL in PHP

How can i call in php words from url? 如何从URL调用php单词?

Example 1 例子1

http://myurl.com/keyword-one

I want to display "Keyword One" as page title in php 我想在PHP中将“关键字一”显示为页面标题

Example 2 例子2

http://myurl.com/keyword/keyword-two

I want to display "Keyword Two" as page title in php 我想在PHP中将“关键字二”显示为页面标题

Thank you! 谢谢! :-) :-)

the simplest solution in those cases would be using (untested code, but should work): 在这种情况下,最简单的解决方案是使用(未经测试的代码,但应该可以):

<?php 
//get path
$urlPath = $_SERVER["REQUEST_URI"];
//get last element
$end = array_slice(explode('/', rtrim($urlPath, '/')), -1)[0];
//replace dashes with spaces and display 
echo ucwords(str_replace('-',' ',$end));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM