Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php get string between two strings

$str = 'before-str-after';
if (preg_match('/before-(.*?)-after/', $str, $match) == 1) {
    echo $match[1];
}
Comment

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>
Comment

PREVIOUS NEXT
Code Example
Php :: php milliseconds 
Php :: Composer install : Your requirements could not be resolved to an installable set of packages 
Php :: increase xampp phpmyadmin import limit 
Php :: php session regenerate id 
Php :: merge two objects in php 
Php :: searching and removing element from an array php 
Php :: carbon parse from format 
Php :: Check duplicate email in laravel using jQuery 
Php :: php copy url 
Php :: how to add data to the request object in laravel 
Php :: In php, how to convert string value into an int 
Php :: wordpress display all variables 
Php :: doctrine php driver execption 
Php :: calculate time difference php 
Php :: php remove slash from string 
Php :: php right characters 
Php :: twig print_r 
Php :: php check regular string 
Php :: shuffle php function 
Php :: add like and equal in same query in laravel 
Php :: get http method php 
Php :: laravel previous url 
Php :: not required a field when checked not applicable checkbox in laravel 
Php :: PHP Forward POST content into Python script 
Php :: carbon add days 
Php :: firebase jwt php verify 
Php :: decode utf-8 php 
Php :: wordpress get post taxonomy terms 
Php :: foreach skip first php 
Php :: php curl ssl certificate problem 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =