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
精彩评论