multi_between()

Last updated on
30 April 2025

Definition

function multi_between($this, $that, $inthat, $check_plain = TRUE) 

This function is used to parse out multiple tag values all at once. This is the only function that does NOT return a string value. It instead returns an array of string values. The best way to describe this function is to simply show some examples.

$this = The beginning string of the tag you are searching for

$that = The end string of the tag you are searching for

$inthat = The string data that contains both $this, $that, and the return value you are looking to get.

$check_plain = Use the check_plain() function. False = disable check_plain()

RETURN VALUES
Returns an array of strings

Examples:
With Check_plain enabled since the stuff we are searching is only text. This stops any unwanted HTML/JS/XML/etc from causing any security problems

$inthis = "Tag: this is tag 1
Tag: this is tag 2
Tag: 
Tag: this it tag 4
";

$start_tag = "Tag: "; //Notice the space after the : It simply eliminates the need to use trim() and nothing more.  Otherwise our values would come back with the space in them which is probably not desired.
$end_tag = "\n";

$all_values = multi_between($start_tag, $end_tag, $inthis);
//Value of $all_tags is now array('0' => 'this is tag 1', '1' => 'this is tag 2', '2' => '', '3' => 'this is tag 4')

With Check_plain DISABLED since the stuff we are searching is tagged (html, xml, whatever). This disables the security of our function so the value returned should be scrutinized extensively to make sure it doesnt open any cross-site scripting holes.

$inthis = "<tag>this is tag 1</tag><tag>this is tag 2</tag><tag></tag><tag>this it tag 4</tag>";

$start_tag = "<tag>"; 
$end_tag = "</tag>";

$all_values = multi_between($start_tag, $end_tag, $inthis, FALSE);
//Value of $all_tags is now array('0' => 'this is tag 1', '1' => 'this is tag 2', '2' => '', '3' => 'this is tag 4')

Help improve this page

Page status: Not set

You can: