Posted in php functions
2660
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
26
This Month
186
This Year
421

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
All of humanity's problems stem from man's inability to sit quietly in a room alone, wrote Blaise Pascal.
Unknown
Random CSS Property

inline-size

The inline-size CSS property defines the horizontal or vertical size of an element's block, depending on its writing mode. It corresponds to either the width or the height property, depending on the value of writing-mode.
inline-size css reference