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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.