sylvain Posted May 12, 2011 Share Posted May 12, 2011 Hi! I'm working a on wordpress website with member pages. Members enter their information via custom fields. Everything is working great except when trying to create a link based on one of those custom field. Unless the member enter his website address in the http://mysite.com format the link my code create is not valid. This is the code i'm currently using <?php $msite = get_post_meta($post->ID, 'ccio_site', true) ; if (!empty($msite)) { ?><li>Site Internet: <a href="<?php echo ($msite) ; ?>"><?php echo ($msite) ; ?></a></li><?php } ?> Example of a member page where the format create an error. The input field is: www.pechabot.com Example of a member page where the format is ok. The input field is http://www.annuairesgb.com How can I format the input string so my code will work even if someone doesn't write the full address with the http:? Thanks a lot for looking Link to comment https://forums.phpfreaks.com/topic/236253-formating-link-input/ Share on other sites More sharing options...
drisate Posted May 12, 2011 Share Posted May 12, 2011 You can check if the http:// string exist and add it if not if (!strstr($string, "http://") ) {echo "http://";} echo $string; Link to comment https://forums.phpfreaks.com/topic/236253-formating-link-input/#findComment-1214656 Share on other sites More sharing options...
sylvain Posted May 12, 2011 Author Share Posted May 12, 2011 Wow! that was quick and simple. I really wish I knew what I was doing when it comes down to php Thanks a lot for your help! Link to comment https://forums.phpfreaks.com/topic/236253-formating-link-input/#findComment-1214664 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.