PDA

View Full Version : Search for a string


3lr0n
08-13-2006, 11:11 PM
Hi.. im new to php and i revised the docs on php.net, but i cant find anything that suits me for my "problem".

Ill try to explain:

Im using xoops, a CMS coded in php. I have a section in which i post articles, those articles are paginated by a class (pagenav.php) of xoops, but the code that build the paginate count each page using explode and the separator bbcode (pagebreak)

$body_parts = explode('[pagebreak]', $body);

body is the main text of the article and here body parts the total number of pages.

What i want to do is to assing an individual name to each page so i thought about introducing a new bbcode name which will be translated into a title, but as long as is in the $body i need a fuction that searchs the [name] string and returns the string inside [name]string for each one of the strings of the explode.

The funcionality of this is to have an article section paginated by a dropdown box instead of numbers.

Any help will be appreciated.

Ta in advance.

Phill
08-14-2006, 12:02 AM
Try something like this:


$names = array();
$tag = 'name';

foreach ($body_parts as $body)
{
if (stripos($body, "[$tag]" !== false)
{
$pos1 = stripos($body, "[$tag]" + strlen("[$tag]"));
$pos2 = stripos($body, "[/$tag]");
$names[] = substr($body, $pos1, $pos2 - $pos1);
}
}


Something like that...

DISCLAIMER: I'm rather tired, I haven't tested this, code may be inefficient and / or inaccurate :D