NoPHPPhD Posted January 25, 2009 Share Posted January 25, 2009 You guys really got me going in the right direction a while ago. I have a huge html file and I wanted to be able to output the contents of the file using echo. Suggestion from forum was to use file_get_contents(). Worked like a champ! So, in this huge html file I have a string (used like a delimiter) for each section, each section is a row, or rowspan. I wanted to just get that piece between the delimeters. Here is the setup to do just this. It finds 1st string, 2nd string, then returns a string of all the text inbetween... TextBetween function courtesy of 'mvp at mvpprograms dot com'. <?php $linenum=''; $content=''; $linenum = file_get_contents("myhtmlfile.html"); echo "<table>"; echo (TextBetween('<!-- Line# 23 -->','<!-- Line# 24 -->',$linenum )); echo "<table/>"; function TextBetween($s1,$s2,$s){ $s1 = strtolower($s1); $s2 = strtolower($s2); $L1 = strlen($s1); $scheck = strtolower($s); if($L1>0){$pos1 = strpos($scheck,$s1);} else {$pos1=0;} if($pos1 !== false){ if($s2 == '') return substr($s,$pos1+$L1); $pos2 = strpos(substr($scheck,$pos1+$L1),$s2); if($pos2!==false) return substr($s,$pos1+$L1,$pos2); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/142363-followup-on-echo-contents-of-html-file-text-between-2-strings/ Share on other sites More sharing options...
zq29 Posted January 26, 2009 Share Posted January 26, 2009 preg_match() Quote Link to comment https://forums.phpfreaks.com/topic/142363-followup-on-echo-contents-of-html-file-text-between-2-strings/#findComment-746504 Share on other sites More sharing options...
.josh Posted January 26, 2009 Share Posted January 26, 2009 I see at one point in time you mentioned what you want, but then say that 'setup' does just that. So...was there a question in there somewhere? Quote Link to comment https://forums.phpfreaks.com/topic/142363-followup-on-echo-contents-of-html-file-text-between-2-strings/#findComment-746512 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.