jigen7 Posted September 11, 2007 Share Posted September 11, 2007 i need help.. suppose i have a variable with a site for example $string = "http://scuba.about.com/cs/snorkelgear/bb/snorkelequip.htm" what i need is i need to remove the string after .com so the remaining string would become like this http://scuba.about.com/ or http://scuba.about.com what function should i use?? thx Link to comment https://forums.phpfreaks.com/topic/68781-solved-helpremoving-strip-the-string-after-com/ Share on other sites More sharing options...
effigy Posted September 11, 2007 Share Posted September 11, 2007 substr and strpos. Link to comment https://forums.phpfreaks.com/topic/68781-solved-helpremoving-strip-the-string-after-com/#findComment-345747 Share on other sites More sharing options...
jigen7 Posted September 11, 2007 Author Share Posted September 11, 2007 oki thx it works heres my coding $action = "http://scuba.about.com/cs/snorkelgear/bb/snorkelequip.htm"; $subpos = 23; $action = substr($action, 0, $subpos); echo $action; but still if the site or the site variable is generated by random how would i know what would be its $subpos??? it would not be always 23 ?? Link to comment https://forums.phpfreaks.com/topic/68781-solved-helpremoving-strip-the-string-after-com/#findComment-345754 Share on other sites More sharing options...
jigen7 Posted September 11, 2007 Author Share Posted September 11, 2007 i need help.. suppose i have a variable with a site for example $string = "http://scuba.about.com/cs/snorkelgear/bb/snorkelequip.htm" what i need is i need to remove the string after .com so the remaining string would become like this http://scuba.about.com/ or http://scuba.about.com also the site variable there is random site so it would not be always http://scuba.about.com/cs/snorkelgear/bb/snorkelequip.htm so i need to determine how to find the .com string what ever site is given then after that i just need to delete the string after the .com what function should i use?? thanks Link to comment https://forums.phpfreaks.com/topic/68781-solved-helpremoving-strip-the-string-after-com/#findComment-345757 Share on other sites More sharing options...
btherl Posted September 11, 2007 Share Posted September 11, 2007 The cleanest way is with parse_url() $action = "http://scuba.about.com/cs/snorkelgear/bb/snorkelequip.htm"; $action_parts = parse_url($action); var_dump($action_parts); var_dump() will show you the contents of $action_parts, so you can see what's inside and choose which parts to use. You would remove it in your final code. Link to comment https://forums.phpfreaks.com/topic/68781-solved-helpremoving-strip-the-string-after-com/#findComment-345758 Share on other sites More sharing options...
jigen7 Posted September 11, 2007 Author Share Posted September 11, 2007 oki thx then how do i choose it after the var_dump?? it prints the line array(3) { ["scheme"]=> string(4) "http" ["host"]=> string(15) "scuba.about.com" ["path"]=> string(35) "/cs/snorkelgear/bb/snorkelequip.htm" } then how can i also hide the txt when using var_dump Link to comment https://forums.phpfreaks.com/topic/68781-solved-helpremoving-strip-the-string-after-com/#findComment-345763 Share on other sites More sharing options...
jigen7 Posted September 11, 2007 Author Share Posted September 11, 2007 ok thx for everyone replying i got the syntax and i made a functin of it here how it goes function strip_com ($value) { $url = "http://scuba.abocdxcdscdut.com/cs/snorkelgear/bb/snorkelequip.htm"; $findme = '.com'; $pos = strpos($url, $findme); // Note our use of ===. Simply == would not work as expected // because the position of 'a' was the 0th (first) character. if ($pos === false) { echo "The string '$findme' was not found in the string '$mystring' <br>"; } else { echo "The string '$findme' was found in the string '$mystring'<br>"; echo " and exists at position $pos<br>"; } $url = substr($url, 0, $pos+4); return $url; } Link to comment https://forums.phpfreaks.com/topic/68781-solved-helpremoving-strip-the-string-after-com/#findComment-345786 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.