I'm searching one PHP function or other solution for my problem.
So, I have a string, this:
$string = 'dfdfdjdkfjsdklfjdksfjekrjekjfdlkfjsdlfdflokuki48(malac)kjdkfdjfkjkejrkerjer';
I'm searching one function, that it has the next parameters:
functionName ($string, $fromCharacters, $toCharacters);
And I run this function:
functionName ($string, 'lokuki48(', ')');
And I will get this: 'malac',
or max. this: 'lokuki48(malac)'.
Do you know about PHP function or solution for my problem?
I hope you understand my problem.
Thank you!
try this,
$string = 'dfdfdjdkfjsdklfjdksfjekrjekjfdlkfjsdlfdflokuki48(malac)kjdkfdjfkjkejrkerjer';
if (strpos($string, 'malac') !== false)
{
echo 'true';
}
else
{
echo 'false';
}
i hope it will be helpful.
The strstr() function searches for the first occurrence of a string inside another string.
Example
Find the first occurrence of "world" inside "Hello world!" and return the rest of the string:
<?php
echo strstr("Hello world!","world");
?>
Thanks Guys!
I have found the solution:
`$string = 'dfdfdjdkfjsdklfjdksfjekrjekjfdlkfjsdlfdflokuki48(fasza)kjdkfdjfkjkejrkerjer';
function get_string_between($string, $start, $end){
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}
echo get_string_between($string,"lokuki48(",")");`
If you love lókuki, use preg_match:
<?php
function search($string, $start, $end)
{
preg_match("'".$start."(.*)".$end."'sim", $string, $out);
if(isset($out[1])) {
return $out[1];
}
return false;
}
$string = 'dfdfdjdkfjsdklfjdksfjekrjekjfdlkfjsdlfdflokuki48(malac)jdkfdjfkjkejrkerjer';
$start="lokuki48\(";
$end="\)";
$res = search($string, $start, $end);
echo $res."
";
$string = 'dfdfdjdkfjsdklfjdksfjekrjekjfdlkfjsdlfdftestfunction(param1, param2)jdkfdjfkjkejrkerjer';
$start="testfunction\(";
$end="\)";
$res = search($string, $start, $end);
echo $res;