rossh Posted November 2, 2006 Share Posted November 2, 2006 Hi i want to be able to remove everything after a question mark in a string. Can someone help me out.ThanksRoss Link to comment https://forums.phpfreaks.com/topic/25948-remove-everything-after-a-certain-character-in-a-string/ Share on other sites More sharing options...
roopurt18 Posted November 2, 2006 Share Posted November 2, 2006 [code]<?php$string = 'Hello, World! How are you? It looks like you\'re fine!';$string = explode('?', $string);$string = $string[0];echo $string;?>Outputs:Hello, World! How are you?[/code] Link to comment https://forums.phpfreaks.com/topic/25948-remove-everything-after-a-certain-character-in-a-string/#findComment-118520 Share on other sites More sharing options...
ruano84 Posted November 2, 2006 Share Posted November 2, 2006 Hi,This is a way to do it:[code]<?php$chain="abcde?edcba";$chr_pos=strpos($chain,"?");$final_chain=substr($chain,0,$chr_pos);echo $chain;?>[/code]I Hope it could help you Link to comment https://forums.phpfreaks.com/topic/25948-remove-everything-after-a-certain-character-in-a-string/#findComment-118524 Share on other sites More sharing options...
Nicklas Posted November 2, 2006 Share Posted November 2, 2006 or slightly optimated[code]<?php$string = 'Hello, World! How are you? It looks like you\'re fine!';list($string) = explode('?', $string);echo $string;?>[/code] Link to comment https://forums.phpfreaks.com/topic/25948-remove-everything-after-a-certain-character-in-a-string/#findComment-118525 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.