2010-03-19 20 views
2

我有SEF的网址,例如/ sitename/section/12-news-title,12号是新闻的id。我需要在我的php代码中获得第12个数字,PHP中是否有任何开箱即用的方法?在PHP中解析SEF url中的数字值

+0

你已经在字符串中添加了'/ sitename/section/12-news-title'吗? – Gumbo 2010-03-19 12:12:21

+0

是的,我已经有 – newbie 2010-03-19 12:15:26

回答

1

取决于您的网址如何被操纵。它会像$_GET['id']之类的东西,但很难说没有看到你的网址如何改变。看看你的.htaccess文件,你应该可以解决它。

+0

好吧,我使用Joomla! – newbie 2010-03-19 12:28:35

3
<?php 

$_GET['id'] = "/sitename/section/12news-title"; // For example 
if (preg_match ('/\d+/',$_GET['id'] ,$val)) 
{ 
print_r ($val) ; // Now $val will have the matched things. 
} 
else 
{ 
print "Not matched \n"; 
} 

?>