【发布时间】:2012-01-25 08:54:45
【问题描述】:
我目前正在编辑带有自定义字段输出的 wordpress 主题。
我已成功进行所有编辑,一切正常。
我的问题是,如果将 url 提交到自定义字段中,回显正是其中的内容,因此如果有人输入 www.somesite.com,回显就是这样并将其添加到域的末尾:www.mysite .com www.somesite.com 。
我想检查提供的链接是否在开头有http:// 前缀,如果它有然后做两者,但如果没有在url 之前回显http://。
我希望我已经尽可能详细地解释了我的问题。
$custom = get_post_meta($post->ID, 'custom_field', true);
<?php if ( get_post_meta($post->ID, 'custom_field', true) ) : ?>
<a href="<?php echo $custom ?>"> <img src="<?php echo bloginfo('template_url');?>/lib/images/social/image.png"/></a>
<?php endif; ?>
【问题讨论】:
-
好吧,您似乎知道如何使用类和模板。即使您不知道如何使用
RegEx、strncmp或许多其他方法中的任何一种,您也应该能够使用substr解决此问题....
标签: php http url if-statement replace