Page 1 of 1

trim the string

Posted: Fri Aug 10, 2007 9:33 am
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]

Posted: Fri Aug 10, 2007 12:19 pm
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;
}
?>

Posted: Sun Aug 12, 2007 5:49 am
by feyd
Don't use split().. explode() instead.