trim the string

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
smilesmita
Forum Commoner
Posts: 30
Joined: Thu May 24, 2007 1:52 pm

trim the string

Post by smilesmita »

pickle | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


hi there,

i have  this:
[syntax="php"]foreach($data2 as $k=>$v){

        $segs = split("_", $k);

        $cn=$segs[sizeof($segs) - 2];

echo $cn;
$cn printouts out to be like this:

#document

CustomerContext

XpciVersion

ResponseStatusCode

what i want is to get rid of #document completely from this string or may be get rid of this character "#" because of which i cannot insert in to DB and it gives error.

any idea?


pickle | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Code: Select all

<?php
foreach($data2 as $k=>$v){

        $segs = split("_", $k);

        $cn=$segs[sizeof($segs) - 2];

        if ($cn == '#document') {
                continue;
        }
        
        echo $cn;
}
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Don't use split().. explode() instead.
Post Reply