SkyRanger Posted April 12, 2011 Share Posted April 12, 2011 Not sure if this is possible. What I am trying to do is remove a section of text a user posts. ie: go to this url: http://url.com or http://this.domain.org I already have it to strip they <a href="whatever but not sure if I can do the other. Any help would be appreciated. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/233487-remove-http/ Share on other sites More sharing options...
spiderwell Posted April 12, 2011 Share Posted April 12, 2011 use str_replace() or substr_replace() Quote Link to comment https://forums.phpfreaks.com/topic/233487-remove-http/#findComment-1200582 Share on other sites More sharing options...
Maq Posted April 12, 2011 Share Posted April 12, 2011 Use: str_replace or if you need to use something a bit more dynamic, then you need regex: preg_replace Quote Link to comment https://forums.phpfreaks.com/topic/233487-remove-http/#findComment-1200584 Share on other sites More sharing options...
drisate Posted April 12, 2011 Share Posted April 12, 2011 You can remove parts of string with str_replace() Ex: $url = str_replace('http://', '', $url); EDIT: lol Maq you beated me hehe Quote Link to comment https://forums.phpfreaks.com/topic/233487-remove-http/#findComment-1200586 Share on other sites More sharing options...
SkyRanger Posted April 12, 2011 Author Share Posted April 12, 2011 Ok how would I do that if it is in the middle of a test ie: Hello visit this site it is cool http://www.thissite.com $comtext = "Hello visit this site it is cool http://www.thissite.com" This is the code i have now: $comname = $rowco['mcname']; $comtext = $rowco['mctext']; echo "<b>"; echo strip_tags($comname); echo "</b><br>"; echo nl2br(strip_tags($comtext)); echo "<hr>"; Quote Link to comment https://forums.phpfreaks.com/topic/233487-remove-http/#findComment-1200595 Share on other sites More sharing options...
Maq Posted April 12, 2011 Share Posted April 12, 2011 We told you what function to use and you didn't even try it... Quote Link to comment https://forums.phpfreaks.com/topic/233487-remove-http/#findComment-1200597 Share on other sites More sharing options...
SkyRanger Posted April 12, 2011 Author Share Posted April 12, 2011 Stupid me, sorry Maq, I overlooked one of the posts. Quote Link to comment https://forums.phpfreaks.com/topic/233487-remove-http/#findComment-1200599 Share on other sites More sharing options...
Maq Posted April 12, 2011 Share Posted April 12, 2011 Stupid me, sorry Maq, I overlooked one of the posts. There was actually 3. Just call the function on the string you want and it will replace all occurrences. Quote Link to comment https://forums.phpfreaks.com/topic/233487-remove-http/#findComment-1200603 Share on other sites More sharing options...
spiderwell Posted April 12, 2011 Share Posted April 12, 2011 someone slap me please Quote Link to comment https://forums.phpfreaks.com/topic/233487-remove-http/#findComment-1200615 Share on other sites More sharing options...
SkyRanger Posted April 12, 2011 Author Share Posted April 12, 2011 Slap me also, I need it...lol. Thanks everyone for you help. Got it working. Quote Link to comment https://forums.phpfreaks.com/topic/233487-remove-http/#findComment-1200623 Share on other sites More sharing options...
SkyRanger Posted April 12, 2011 Author Share Posted April 12, 2011 Guess I never got it working...well sort of. using str_replace I can get the http:// and www. to remove using an array. But is there a way using string replace to remove the who URL that somebody posts. It might be in the str_replace php page but I seem to be overlooking something. $urlgarbage = array("http://", "www."); $comtext = str_replace($urlgarbage, 'BADCODE', $comtexta); echo $comtext; So what I am saying is I would like to do something like: Change: Check out http://www.thissite.tld now. To: Check out BADCODE now. Is this possible using str_replace? Quote Link to comment https://forums.phpfreaks.com/topic/233487-remove-http/#findComment-1200628 Share on other sites More sharing options...
SkyRanger Posted April 12, 2011 Author Share Posted April 12, 2011 Finally got it working: $url_regexp = "(https?://)?(www\.)?([a-zA-z0-9\.])*[a-zA-Z0-9]*\.[a-z]{2,3}"; $cmsg = ereg_replace($url_regexp, '', $comtexta); That did the trick i needed. Quote Link to comment https://forums.phpfreaks.com/topic/233487-remove-http/#findComment-1200647 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.