views:

453

answers:

4

Hi all,

Im Sorry for my bad English

I need help for my problem. When we open page source of HTML page like google, we will found HTML TAG : (in this google was found my string)

<!doctype html><head><title>bla bla bla
<ol><li class="g w0"><h3 class=r>**bla bla bla..**</div></ol>
<ol><li class="g w0"><h3 class=r>**bla bla bla..**</div></ol>
<ol><li class="g w0"><h3 class=r>**bla bla bla..**</div></ol>
</script> <!-- end with no </html> ?? -->

and my problem is : How PHP get all string between <ol> .. </ol>, but keep HTML TAG (inlude <ol> and </ol>). So, all string before first <ol> and after last </ol>, or all string between </ol> and next <ol> will be deleted or not show. I can do this in VB but can't on PHP. Thanks

A: 

You may want to read up on PHP's support of regular expressions.

joeslice
A: 

Hopefully I'm understanding your question correctly, but if not, I appologize.

Starting on a side note: The method you use to get the result you are looking for in VB should be the same method you will use in PHP, but with a different syntax, I presume.

That being said, if you are looking to only the ordered lists on the page, I would recommend doing that with some sort of XML processing. Using XPATH, you should be able to get an array of <ol>...</ol> elements. I would then take those and build the page based off of that. Just using Regex could be painful per the following html string: <ol><li><ol><li>subdata1</li></ol></li></ol>. What you would want is the whole <ol> element, but unless you're clever w/ regex, you will most likely end up with: <ol><li><ol><li>subdata1</li></ol> and miss the last </li></ol>

Anyway, just a thought. I would look first into re-writing your VB app in PHP, but if that is not possible, I recommend reading up a bit on processing XML w/ PHP using XPATH queries.

regex
A: 

You can use the PHP string functions, php regular expression functions or XML parsing functions.

The fastest would be to use string functions like strpos() and substr(). However, regular expressions with preg_match() or XML functions like with SimpleXML are easier to use.

bucabay
A: 

This my VB code :

Dim start_string As String
Dim end_string As String
dim g as string

On Error Resume Next
start_string = "<tr>"
end_string = "</tr>"
st = 1
Data = (URL)

s = InStr(st, Data, start_string, 1)
While s > 0
d = InStr(Len(start_string) + s, Data, end_string, 1)
g = Mid(Data, s, d - s + Len(end_string))
DoEvents

g = Trim(g)
st = d + 1
s = InStr(st, Data, start_string, 1)
Wend