PHP Classes

ReadReplyBody to an array?

Recommend this page to a friend!

      PHP HTTP protocol client  >  All threads  >  ReadReplyBody to an array?  >  (Un) Subscribe thread alerts  
Subject:ReadReplyBody to an array?
Summary:Possible to obtain reply body from source HTML in an array?
Messages:5
Author:Ryan
Date:2010-12-20 16:10:02
Update:2010-12-21 04:53:26
 

  1. ReadReplyBody to an array?   Reply   Report abuse  
Picture of Ryan Ryan - 2010-12-20 16:10:02
First of all, let me just say that I love your class. This has saved me a lot of time and effort, so thank you.

I have a scenario where I'd like to pull the source HTML (reply body) from a remote website, and parse various information from the source HTML that's returned by the ReadReplyBody function. My question is this. Is there anyway to retrieve that source HTML in an array by line in attempts to save the formatting of the original webpage instead of one long string?

I know that if you use the file() function in PHP you can do this, however with that you cannot modify the headers like you can with your class.

Any help with this would be much appreciated.

Thanks in advance!

-Ryan

  2. Re: ReadReplyBody to an array?   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2010-12-21 00:56:24 - In reply to message 1 from Ryan
You can use the preg_split function to do that.

$array = preg_split('/\\r?\\n?/', $html);

  3. Re: ReadReplyBody to an array?   Reply   Report abuse  
Picture of Ryan Ryan - 2010-12-21 03:29:26 - In reply to message 2 from Manuel Lemos
ahh yes this worked:
$html_lines = preg_split('/\\n/',$body);

Your example with the /\\n?/ will split the string up at every character regardless of if it's a newline or not.

Thank you for the suggestion!!

  4. Re: ReadReplyBody to an array?   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2010-12-21 04:26:11 - In reply to message 3 from Ryan
Right, it should be something like '/\\r\\n|\\r|\\n/' to support all combinations of usual line break sequences.

  5. Re: ReadReplyBody to an array?   Reply   Report abuse  
Picture of Ryan Ryan - 2010-12-21 04:53:26 - In reply to message 4 from Manuel Lemos
Very good. Thank you for your help. This class that you've made is quite impressive and I'm glad to have come across it.