note 73849 added to function.substr
| From: | ankitdotmathur82atyahoodotcom at osu1 dot php dot net | Date: | Tue, 13 Mar 2007 06:22:59 +0000 |
| Subject: | note 73849 added to function.substr | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-124395@lists.php.net to get a copy of this message | ||
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;
?>
----
Server IP: 203.199.114.50
Probable Submitter: 202.71.133.28
----
Manual Page -- http://www.php.net/manual/en/function.substr.php
Edit -- https://master.php.net/note/edit/73849
Del: integrated -- https://master.php.net/note/delete/73849/integrated
Del: useless -- https://master.php.net/note/delete/73849/useless
Del: bad code -- https://master.php.net/note/delete/73849/bad+code
Del: spam -- https://master.php.net/note/delete/73849/spam
Del: non-english -- https://master.php.net/note/delete/73849/non-english
Del: in docs -- https://master.php.net/note/delete/73849/in+docs
Del: other reasons-- https://master.php.net/note/delete/73849
Reject -- https://master.php.net/note/reject/73849
Search -- https://master.php.net/manage/user-notes.php