php find multiple strings in string
if(preg_match('(bad|naughty)', $data) === 1) { }
php find multiple strings in string
if(preg_match('(bad|naughty)', $data) === 1) { }
How to get a substring between two strings in PHP?
<!DOCTYPE html>
<html>
<body>
<?php
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);
}
$fullstring = '.layout {
color: {{ base_color }}
}
li {
color: {{ sub_color }}
}
.text {
color: {{ txt_color }}
}
.btn {
color: {{ btn_color }}
}
.more_text{
color:{{more_color}}
}';
$arr = [];
while(1){
$parsed = get_string_between($fullstring, '{{', '}}');
if(!$parsed)
break;
array_push($arr,$parsed);
$strposition = strpos($fullstring,"}}");
$nextString = substr($fullstring, $strposition+1, strlen($fullstring));
$fullstring = $nextString;
echo "<br>";
}
print_r($arr);
?>
</body>
</html>
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us