Jump to content

Building and array


denoteone

Recommended Posts

I have a function that opens a web page and then builds and array by scrubbing the page.

 

i dont understand how the array is looking for the data can anyone help me with this?

 

		$quote_data = array(
		"Name" => array("pattern" => "/<h1>([^<]+?)<\/h1>/", "value" => "N/A"),
		"Last" => array("pattern" => "/:.+?<big><b>(.+?)<\/b><\/big>/", "value" => "N/A"),
		"Time" => array("pattern" => "/Trade Time:<\/td><td.+?>(.+?)<\/td>/", "value" => "N/A"),
		"Date" => array("pattern" => "", "value" => "N/A"),
		"Change" => array("pattern" => "/Change:<\/td><td.+?alt=\"(.+?)\">.+?>(.+?)<\/b>.+?>\s+(.+?)<\/b>/", "value" => "N/A"),
		"PercentageChange" => array("pattern" => "", "value" => "N/A"),
		"PreviousClose" => array("pattern" => "/Prev Close:<\/td><td.+?>(.+?)<\/td>/", "value" => "N/A"),
		"Open" => array("pattern" => "/Open:<\/td><td.+?>(.+?)<\/td>/", "value" => "N/A"),
		"High" => array("pattern" => "/Day's Range:<\/td><td.+?>(.+?)<\/td>/", "value" => "N/A"),
		"Low" => array("pattern" => "", "value" => "N/A"),
		"AnnRange" => array("pattern" => "/52wk Range:<\/td><td.+?>(.+?)<\/td>/", "value" => "N/A"),
		"Volume" => array("pattern" => "/Volume:<\/td><td.+?>(.+?)<\/td>/", "value" => "N/A"),
		"MktCap" => array("pattern" => "/Market Cap:<\/td><td.+?>(.+?)<\/td>/", "value" => "N/A"),
		"P-E" => array("pattern" => "/P\/E .+?<td.+?>(.+?)<\/td>/", "value" => "N/A"),
		"Earns" => array("pattern" => "/EPS .+?<td.+?>(.+?)<\/td>/", "value" => "N/A")
	);

Link to comment
https://forums.phpfreaks.com/topic/150346-building-and-array/
Share on other sites

let me try this differently my RegEx is

 

/:.+?<big><b>(.+?)<\/b><\/big>/

 

the string it is searching is   

<big><b><span id="yfs_l10_^dji">7,403.58</span></b></big>

 

what it getting is

<span id="yfs_l10_^dji">7416.41</span>

 

i need the Regex to get only what is between the span.... ???  I do not need the span tag in there...

 

 

Link to comment
https://forums.phpfreaks.com/topic/150346-building-and-array/#findComment-789651
Share on other sites

ok, well this is a very inelegant way to do it, but this is how I normally parse info out of stuff

 

try

 

/:.+?<big><b><span.*?>(.*?)</span><\/b><\/big>/

 

I use .*? as a way of saying "skip over whatever is here"

 

and (.*?) for "grab whatever is here"

 

Hope that helps.

Link to comment
https://forums.phpfreaks.com/topic/150346-building-and-array/#findComment-789754
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.