-entropyman Posted July 18, 2008 Share Posted July 18, 2008 Hello, I am working on returning a portion of a string between two key words. However, I have not had much luck lol. So far I have: <?php $filename = ("http://xxxxxxxxxxxxx/xzcz.txt"); $filestring = file_get_contents($filename); $domain = strstr($filestring, 'FirstWord'); $new = stristr($domain, 'LastWord', true); echo $new; ?> Can anyone help? ??? Link to comment https://forums.phpfreaks.com/topic/115432-solved-returning-portion-of-string/ Share on other sites More sharing options...
unkwntech Posted July 18, 2008 Share Posted July 18, 2008 Please post an example input and and example of what output you need. Link to comment https://forums.phpfreaks.com/topic/115432-solved-returning-portion-of-string/#findComment-593415 Share on other sites More sharing options...
JasonLewis Posted July 18, 2008 Share Posted July 18, 2008 I managed to do it... A different way, not sure if its the best but eh: $firstWord = "Hello"; $lastWord = "people"; $str = "Hello there, my golly there is a lot of people here!"; $str = substr($str, strpos($str,$firstWord)+strlen($firstWord),strpos($str,$lastWord)-strlen($lastWord)); echo $str; strstr() wasn't working for me... So I did it like that. Link to comment https://forums.phpfreaks.com/topic/115432-solved-returning-portion-of-string/#findComment-593429 Share on other sites More sharing options...
-entropyman Posted July 18, 2008 Author Share Posted July 18, 2008 Thank you ProjectFear! Perfect! :D Link to comment https://forums.phpfreaks.com/topic/115432-solved-returning-portion-of-string/#findComment-593459 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.