note 44161 added to function.substr
| From: | ross at noxware dot co dot uk | Date: | Fri, 16 Jul 2004 10:36:18 +0000 |
| Subject: | note 44161 added to function.substr | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-73376@lists.php.net to get a copy of this message | ||
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.
----
Manual Page -- http://www.php.net/manual/en/function.substr.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+44161
Delete -- http://master.php.net/manage/user-notes.php?action=delete+44161&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+44161&report=yes
Search -- http://master.php.net/manage/user-notes.php