Welcome Guest, Not a member yet? Register   Sign In
Simple string task ?! :)
#1

[eluser]ven_dev[/eluser]
I almost finished my first CI website,however I have a little problem now.
On my local pc my php version is 5.3 but on the server its 5.2.*

In my core I use strstr() function with the third parrameter bool.(not supported in <5.3)

What I need to do is:

$string = 'some different string every time where my need is missing in this strange string';
$before = 'string';
$after = 'missing';

And what I need to get is the code between 'string' and 'missing'.
And the final need is 'every time where my need is';

The words string and missing are always there,only the answer is different everytime.

I hope I explained it good.
Please help me you good coders Tongue
#2

[eluser]J. Pavel Espinal[/eluser]
Hi there,

Although that is not a CI specific question, I'll keep the collaborative spirit of CI's community.

This might serve you as a guide:

Code:
/* @var $lsSubject string */
$lsSubject   = 'some different string every time where my need is missing in this strange string';
/* @var $lsLftLimit string */
$lsLftLimit = 'string';
/* @var $lsRgtLimit string */
$lsRgtLimit = 'missing';
/* @var $lsPattern string */
$lsPattern = '/'.$lsLftLimit .' (.*) '. $lsRgtLimit.'/';


if(@preg_match($lsPattern, $lsSubject,$laMatches) == 0)
{
    // Pattern not found... do whatever you want here
}
else {
    print_r($laMatches);
}

// Output:
// Array
// (
//     [0] => string every time where my need is missing
//     [1] => every time where my need is
// )
// The second element of the $laMatches array should have your desired result.

#3

[eluser]ven_dev[/eluser]
Thank you man!
Really helpfull , cheers Smile




Theme © iAndrew 2016 - Forum software by © MyBB