Organizational Research By

Surprising Reserch Topic

get substring between two strings php


get substring between two strings php  using -'php,substring'

I need a function that returns the substring between two words (or two characters).
I'm wondering whether there is a php function that achieves that. I do not want to think about regex (well, I could do one but really don't think it's the best way to do that). Thinking of strpos and substr functions.
Here's an example:

$string = "foo I wanna a cake foo";


We call the function: $substring = getInnerSubstring($string,"foo");
It returns: " I wanna a cake ".

Thanks in advance.

Update:
Well, till now, I can just get a substring beteen two words in just one string, do you permit to let me go a bit far and ask if I can extend the use of getInnerSubstring($str,$delim) to get any strings that are between delim value, example:

$string =" foo I like php foo, no foo I like asp foo, foo go to hell foo";


Maybe I get an array like {"I like php", "I like asp", "go to hell"}.
    

asked Sep 21, 2015 by ankitarajoria4
0 votes
20 views



Related Hot Questions

17 Answers

0 votes
NULL
answered Sep 21, 2015 by akasati02
0 votes
NULL
answered Sep 21, 2015 by gauravsinghal83
0 votes
NULL
answered Sep 21, 2015 by shegokar.anjeet
0 votes
NULL
answered Sep 21, 2015 by badhwar.rohit
0 votes
NULL
answered Sep 21, 2015 by kotmus2002
0 votes
NULL
answered Sep 21, 2015 by sameer rathore
0 votes
NULL
answered Sep 21, 2015 by amit.gupta
0 votes
NULL
answered Sep 21, 2015 by maurya
0 votes
NULL
answered Sep 21, 2015 by yogeshplv
0 votes
NULL
answered Sep 21, 2015 by gauravg.gwl
0 votes
NULL
answered Sep 21, 2015 by ankitarajoria4
0 votes
NULL
answered Sep 21, 2015 by amit_cmps
0 votes
NULL
answered Sep 21, 2015 by okesh.badhiye
0 votes
NULL
answered Sep 21, 2015 by badhwar.rohit
0 votes
NULL
answered Sep 21, 2015 by atulpariharmca
0 votes
NULL
answered Sep 21, 2015 by 20shahi
0 votes
NULL
answered Sep 21, 2015 by bhavin

...