Voting

: nine plus zero?
(Example: nine)

The Note You're Voting On

biohazard dot ge at gmail dot com
11 years ago
may be by following functions will be easier to extract the needed sub parts from a string:

<?php
after
('@', '[email protected]');
//returns 'online.ge'
//from the first occurrence of '@'

before ('@', '[email protected]');
//returns 'biohazard'
//from the first occurrence of '@'

between ('@', '.', '[email protected]');
//returns 'online'
//from the first occurrence of '@'

after_last ('[', 'sin[90]*cos[180]');
//returns '180]'
//from the last occurrence of '['

before_last ('[', 'sin[90]*cos[180]');
//returns 'sin[90]*cos['
//from the last occurrence of '['

between_last ('[', ']', 'sin[90]*cos[180]');
//returns '180'
//from the last occurrence of '['
?>

here comes the source:

<?php

function after ($this, $inthat)
{
if (!
is_bool(strpos($inthat, $this)))
return
substr($inthat, strpos($inthat,$this)+strlen($this));
};

function
after_last ($this, $inthat)
{
if (!
is_bool(strrevpos($inthat, $this)))
return
substr($inthat, strrevpos($inthat, $this)+strlen($this));
};

function
before ($this, $inthat)
{
return
substr($inthat, 0, strpos($inthat, $this));
};

function
before_last ($this, $inthat)
{
return
substr($inthat, 0, strrevpos($inthat, $this));
};

function
between ($this, $that, $inthat)
{
return
before ($that, after($this, $inthat));
};

function
between_last ($this, $that, $inthat)
{
return
after_last($this, before_last($that, $inthat));
};

// use strrevpos function in case your php version does not include it
function strrevpos($instr, $needle)
{
$rev_pos = strpos (strrev($instr), strrev($needle));
if (
$rev_pos===false) return false;
else return
strlen($instr) - $rev_pos - strlen($needle);
};
?>

<< Back to user notes page

To Top