Posted in php functions
2681
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
24
This Month
70
This Year
442

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
Even if you fall on your face, you're still moving forward.
Victor Kiam
Random CSS Property

cross-fade()

The cross-fade() CSS function can be used to blend two or more images at a defined transparency. It can be used for many simple image manipulations, such as tinting an image with a solid color or highlighting a particular area of the page by combining an image with a radial gradient.
cross-fade() css reference