开发者

PHP base_url returning site, append variable strings to it? [closed]

开发者 https://www.devze.com 2023-04-03 20:44 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

I'm trying to use PHP to generate a URL, from a database.

This is the script so far:开发者_JS百科 (snippet)

$data['url'] = site_url('/'.$row['pid']);

That shows http://www.domain.com/index.php/pid-variable-from-SQL

I'm trying to use base_url to return the same URL except without the index.php part. It works, except chops off the /pid-stuff part.

Any help? Or why does this code not work?

$data['url'] = base_url('/'.$row['pid']);


You could use regex to pluck out the index.php part of the URL.

$data['url'] = preg_replace("/(^http:\/\/.*?)\/(.*?)(\/.*)/", '$1$3', site_url('/'.$row['pid'])); //Should return http://www.domain.com/pid-variable-from-SQL
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号