note 44161 deleted from function.substr by tomsommer

From: Date: Fri, 16 Jul 2004 10:44:46 +0000
Subject: note 44161 deleted from function.substr by tomsommer
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-73377@lists.php.net to get a copy of this message
Note Submitter: ross@noxware.co.uk ---- I have just had hell making a forum, with only one database, using a 'topic' field to filter all the messages in to their subtopics, ie hello.hi.me.no.fred.text.files.thingy. , where each string seperated by a '.' will be the name of a topic. I created the following function to split these into their components and store it in an array... hopefully this will be of some use: <? // ross@noxware.co.uk designed goto noxware.co.uk for // // web design and PHP constrution! // $n = 1; $topic = "hello.hi.me.no.fred.text.files.thingy."; $needle = "."; while ( $topic != "" ) { $top[$n] = substr("$topic",0,strpos($topic,$needle)); // $top[$n] = hello $topic = strstr($topic, '.'); // $topic = .hi.me.no $topic = substr($topic, 1); // hi.me.no $n ++; } // display results of array. while ( $n > 0 ) { echo $top[$n] . ' '; $n = $n -1; } ?> OUTPUT: " thingy files text fred no me hi hello " PLEASE NOTE: must be a fullstop at the end of the string! otherwise the last note will be missed out. Cheers, Ross.

« previous php.notes (#73377) next »