我有一个优惠券网站,显示我的商店网页上的商店网址。我想要的是在每个商店的末尾只有.com,而不是在开始时显示
这是我的代码,它显示了一个商店的url,我只想显示domain.com而不是http://www.domain.com,也可以显示为http://domain.com
<p class="store-url"><a href="<?php echo $url_out; ?>" target="_blank"><?php echo $stores_url; ?>由于此函数,它的显示如下所示
<div class="store">
<?php // grab the store meta data
$term = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy'));
$stores_url = esc_url(get_metadata(APP_TAX_STORE, $term->term_id, 'clpr_store_url', true));
$dest_url = esc_url(get_metadata(APP_TAX_STORE, $term->term_id, 'clpr_store_aff_url', true));
// if there's a store aff link, then cloak it. else use store url
if ($dest_url)
$url_out = esc_url(home_url(CLPR_STORE_REDIRECT_BASE_URL . $term->slug));
else
$url_out = $stores_url;
?>可做的事.
发布于 2012-08-01 15:24:42
快速和肮脏-演示可能的功能...
<?php
function cleanInputString($inputString) {
// lower chars
$inputString = strtolower($inputString);
// remove whitespaces
$inputString = str_replace(' ', '', $inputString);
// check for .com at the end or add otherwise
if(substr($inputString, -4) == '.com') {
return $inputString;
} else {
return $inputString .'.com';
}
}
// example
$inputStrings = array(
'xyzexamp.com',
'xyzexamp',
'xyz examp'
);
foreach($inputStrings as $string) {
echo('input: '. $string .'; output: '. cleanInputString($string) .'<br />');
}
?>输出:
input: xyzexamp.com; output: xyzexamp.com
input: xyzexamp; output: xyzexamp.com
input: xyz examp; output: xyzexamp.com发布于 2012-08-03 02:46:24
“正确的方式”可能是使用PHP URL处理:
使用http://php.net/manual/en/function.parse-url.php
取消设置
https://stackoverflow.com/questions/11754297
复制相似问题