before()

Last updated on
30 April 2025

DEFINITION

function before($this, $inthat, $check_plain = TRUE)

This function returns the whole string that comes before $this string in the $inthat variable. If there is no string $this in the $inthat variable then the return value is null.

$this = The tag you are searching for

$inthat = The text you are trying to search in

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

RETURN VALUES
Returns a string value

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 = "Angelina Jolie (born Angelina Jolie Voight on June 4, 1975) is an American film actor and a Goodwill Ambassador for the UN Refugee Agency";

$before = "Voight";
$value = before($before, $inthis);
//$value is now set to 'Angelina Jolie (born Angelina Jolie '

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 = '<b>Angelina Jolie</b> (born <b>Angelina Jolie Voight</b> on June 4, 1975) is an American film actor and a <a href="/wiki/UNHCR_Goodwill_Ambassador" title="UNHCR Goodwill Ambassador" class="mw-redirect">Goodwill Ambassador</a> for the <a href="/wiki/UNHCR" title="UNHCR" class="mw-redirect">UN Refugee Agency</a>.';

$before = 'Voight';

$value = before($before, $inthis, FALSE);
//$value is now set to <b>Angelina Jolie</b> (born <b>Angelina Jolie '

Help improve this page

Page status: Not set

You can: