Posted in php functions
2575
5:00 am, June 24, 2022
 

get string between other strings function php

So it turns out that i have had this issue before of finding a string in between other strings and made a function for it that i forgot about. 

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 trim(substr($string,$ini,$len));
	}

$html_string = "<p><strong>Model</strong>:   Kawasaki ZZR 1400&nbsp; (ZX-14)    </p>";

$my_extracted_string = get_string_between(
	$string = $html_string, 
	$start = "<p><strong>Model</strong>:", 
      $end = "</p>"
);

echo "add it into a text area so you can see the raw string as extracted<br>";
echo "<textarea>";
echo $my_extracted_string;
echo "</textarea>";

View Statistics
This Week
35
This Month
197
This Year
336

No Items Found.

Add Comment
Type in a Nick Name here
 
Search Code
Search Code by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code here, mostly for my reference. Also if i find a good link, i usually add it here and then forget about it. more...

Subscribe to weekly updates about things i have added to the site or thought interesting during the last week.

You could also follow me on twitter or not... does anyone even use twitter anymore?

If you found something useful or like my work, you can buy me a coffee here. Mmm Coffee. ☕

❤️👩‍💻🎮

🪦 2000 - 16 Oct 2022 - Boots
Random Quote


James Clear
Random CSS Property

<ratio>

The <ratio> CSS data type, used for describing aspect ratios in media queries, denotes the proportion between two unitless values.
<ratio> css reference