Jump to content
php.lv forumi

http replace


FT3

Recommended Posts

Warning: Invalid argument supplied for foreach() in C:\AppServ\www\index.php on line 4

 

<?php
$links = 'wowowow.lv';
foreach($links as &$link){
 if(substr($link, 0, 7) !== 'http://' and substr($link, 0, 8) !== 'https://')
$link = "http://{$link}";
}

echo $link;
?>

Edited by FT3
Link to comment
Share on other sites

Code Igniter freimworkā pieejamais risinājums

 

 

/**
* Prep URL
*
* Simply adds the http:// part if no scheme is included
*
* @access public
* @param string the URL
* @return string
*/
if ( ! function_exists('prep_url'))
{
function prep_url($str = '')
{
 if ($str == 'http://' OR $str == '')
 {
  return '';
 }
 $url = parse_url($str);
 if ( ! $url OR ! isset($url['scheme']))
 {
  $str = 'http://'.$str;
 }
 return $str;
}
}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...