kannu Posted March 27, 2009 Share Posted March 27, 2009 hello, i have a string $row_cart['prod_img'] which contains the website address which would either being with http or https . how can i check if it begins with htttp, then to replace it with https if you can please help me out on this. thanks Link to comment https://forums.phpfreaks.com/topic/151364-checking-the-value-of-string-for-http-or-https/ Share on other sites More sharing options...
Mark Baker Posted March 27, 2009 Share Posted March 27, 2009 $url = $row_cart['prod_img']; $urlData = parse_url($url); if ($urlData[''scheme] == 'http') { $url = 'https'.substr($url,4); } echo $url; Link to comment https://forums.phpfreaks.com/topic/151364-checking-the-value-of-string-for-http-or-https/#findComment-795005 Share on other sites More sharing options...
kannu Posted March 27, 2009 Author Share Posted March 27, 2009 hi mark, i am getting a syntax error in the code if ($urlData[''scheme] == 'http') { $url = 'https'.substr($url,4); } can you double check this thanks Link to comment https://forums.phpfreaks.com/topic/151364-checking-the-value-of-string-for-http-or-https/#findComment-795018 Share on other sites More sharing options...
Mark Baker Posted March 27, 2009 Share Posted March 27, 2009 if ($urlData['scheme'] == 'http') { $url = 'https'.substr($url,4); } Mea typo.... though you should have been able to see it for yourself Link to comment https://forums.phpfreaks.com/topic/151364-checking-the-value-of-string-for-http-or-https/#findComment-795034 Share on other sites More sharing options...
kannu Posted March 27, 2009 Author Share Posted March 27, 2009 hi Mark thanks for the help. i am learning and still novice in php. but your code works perfectly now. thanks again, and i really appreciate the same thanks Link to comment https://forums.phpfreaks.com/topic/151364-checking-the-value-of-string-for-http-or-https/#findComment-795038 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.