Posted in php functions
2661
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
27
This Month
187
This Year
422

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


seren spirit :(
Random CSS Property

math-style

The math-style property indicates whether MathML equations should render with normal or compact height.
math-style css reference