note 73849 deleted from function.substr by nlopess

From: Date: Sun, 18 Mar 2007 12:34:33 +0000
Subject: note 73849 deleted from function.substr by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-124559@lists.php.net to get a copy of this message
Note Submitter: ankit dot mathur82 at yahoo dot com ---- Hi, Its a very simple way of getting desired output but somehow it took me helluva lot of time. So I'm providing a solution for all the newbies who might be looking for such a solution. SQL Query: Select PlanName FROM Usr_prepaidplan Now, I have few database records like: BPO-WITH-BW#Delhi BPO-WITH-BW#Chennai BPO-WITH-BW#Hyderabad BPO-WITH-BW#Pune BPO-WITH-BW#Kolkata BPO-WITH-BW#Bangalore PCO mumbai plan#GLOBE ELECTRICALS test3 World2Cents Net4Nigeria Problem: My Issue is to remove all characters '#' onwards in only those records which contain a # value. Records that doesn't have # should be displayed as it is. Something like my earlier record "HP_Rate_Plan#New" should look like "HP_Rate_Plan". Solution: <?php $string = $arr['PlanName']; $findme = '#'; $pos = stripos($string, $findme) + strlen($findme); if($pos > 0) $result_string = substr($string,0,$pos); else $result_string = $string; echo $result_string; ?>

« previous php.notes (#124559) next »