Input: string = "10 New from $9.00 40 Used from $0.74";
Desired output: $new = 9.00; $used = 0.74;
I pulled the prices of a book from the source code of a website via cURL, and need to extract the highest ($new_price), and lowest ($used_price) from a segment of the code. Hello, I know this sounds like a very easy issue to get by, but I have put about 5 hours into trying to figure it out and have turned up with nothing. My goal is to remove two prices from a string of source code (gathered by cURL) and store each in its own variable. The problems I keep running into is that I do not know how many digits the price will be (one to four digits), and for some reason I cannot use the function substr(). My only guess is that maybe the "string" I am counting isn't a string at all, but some other data type as it is a section of HTML. Here is what I've tried so far:
Attempt 1: Removed all characters != numbers. I was left with the two numbers, but could not figure out how to separate the two decimals into variables.
Attempt 2: Tried splitting entire string into two pieces, each containing an integer that I could isolate. The problem I ran into was I could not count the string to separate it with substr(). Also, there would have been more than one number in each string, so I would have had to only recognize ints beginning with "$"
Aucun commentaire:
Enregistrer un commentaire