Jump to content

string chops


nadeemshafi9

Recommended Posts

hi guys

 

i have a string, i have a position 1 and position 2, the length of the string is variable

 

i need the text between position 1 and position 2

 

lets call them p1 and p2

 

i am looking at substring substr(text, p1, I DONT KNOW THE LENGTH)

 

i need to work out the length from p1 to p2 in order to use substr

 

ANY help welcome

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/113560-string-chops/
Share on other sites

Uhh....I was thinking:

 

echo substr($string, $p1, $p2-$p1);

 

Let's say $p1 = 3 and $p2 = 7.  He wants between $p1 and $p2.  So he starts at $p1 (first parameter), and goes 4 forward ($p2-$p1). >_>  Unless I'm just going crazy, that's how you do it.  But I very well could be. Kind of just woke up. xD

Link to comment
https://forums.phpfreaks.com/topic/113560-string-chops/#findComment-583515
Share on other sites

Uhh....I was thinking:

 

echo substr($string, $p1, $p2-$p1);

 

Let's say $p1 = 3 and $p2 = 7.  He wants between $p1 and $p2.  So he starts at $p1 (first parameter), and goes 4 forward ($p2-$p1). >_>  Unless I'm just going crazy, that's how you do it.  But I very well could be. Kind of just woke up. xD

 

everyones sayin g thats how u do it, its not making sense to me and its the only thing holding me back how can p2-p1 be the length, 

 

 

eg

 

 

 

.....p1....p2.

 

 

 

p1 = 5

 

p2 = 9

 

p2 - p1 = 3 ???????

 

...

Link to comment
https://forums.phpfreaks.com/topic/113560-string-chops/#findComment-583538
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.