![]() |
|
[PHP] [SOLVED] String within a string. [SOLVED] - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Web Development (https://hackforums.net/forumdisplay.php?fid=183) +---- Thread: [PHP] [SOLVED] String within a string. [SOLVED] (/showthread.php?tid=3124989) |
[SOLVED] String within a string. [SOLVED] - Linux. - Dec 26, 2012 Say for example I download the source code of a page, using cUrl. Now say I want to find a line of that code only, but the problem is the value for it change all the time but it is always in SHA-1 form. I know what line it is located on so really I just need to get that line then I can remove the other values until I get the value I need by its self right? Sorry if I counfused anyone, this is similar to Regex in C# if you know anything about it.😵 Example code: PHP Code * - nibbles - Dec 26, 2012 If your willing to change your code around abit, I've had better luck with DOM. http://php.net/manual/en/book.dom.php Have a look, it can find specific items with ease and less code is needed, I'm still learning about php so I don't know if this way would be faster. * - CarrotMilk - Dec 26, 2012 http://simplehtmldom.sourceforge.net/ Should be fine if I understand your question right. * - Linux. - Dec 26, 2012 (Dec 26, 2012 08:34 AM)nibbles Wrote: If your willing to change your code around abit, I've had better luck with DOM. Can you give me an example? If so thank you so much ! * - nibbles - Dec 26, 2012 Have a look at what CarrotMilk posted, looking at it it's pretty straight forward. It's alot simpler than what's in the php manual... PHP Code * - Linux. - Dec 26, 2012 (Dec 26, 2012 08:49 AM)nibbles Wrote: Have a look at what CarrotMilk posted, looking at it it's pretty straight forward. Can I search for tag names? Not like the tag id's but the names since the tag I want has no id only a name. (Dec 26, 2012 08:45 AM)CarrotMilk Wrote: http://simplehtmldom.sourceforge.net/ Thank! I will take a moment and code it then post back see if anything could be simplifed and what not. * - nibbles - Dec 26, 2012 Looking at I would say something like this? PHP Code If your looking for a match try this? PHP Code Edit: Just re-read your question, this might be what your looking for PHP Code * - Linux. - Dec 26, 2012 I got a error with this code: PHP Code Says that "file_get_html" is a undefinded function. * - nibbles - Dec 26, 2012 PHP Code Give that a go :) * - Linux. - Dec 26, 2012 I downloaded it, and included the file here is the current code: PHP Code Here is the new error: Warning: file_get_contents(http://www.twitter.com): failed to open stream: Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? in C:\Users\CENSORED\Desktop\xampp\htdocs\simple_html_dom.php on line 75 Fatal error: Call to a member function find() on a non-object in C:\Users\CENSORED\Desktop\xampp\htdocs\index.php on line 6 * - CarrotMilk - Dec 26, 2012 Try using cURL to grab the content of the page and save it to the $html var. * - nibbles - Dec 26, 2012 Go to your "php.ini" file and find "extension=php_openssl.dll" and remove the semicolon then restart your xampp server * - Yoshi- - Dec 26, 2012 You need to enable ssl first, but ssl is not even needed, the html_dom stuff is just written "badly". Use a Regex, don't even bother parsing HTML is it pretty much pointless. Something like this: PHP Code Or if you want to use curl PHP Code * - CarrotMilk - Dec 26, 2012 "Don't even bother parsing HTML [..]" wut whai. It's a terrible idea to parse HTML with RegEx. * - Yoshi- - Dec 26, 2012 (Dec 26, 2012 09:47 AM)CarrotMilk Wrote: "Don't even bother parsing HTML [..]" Reread what I said please. In this case Regex is the best thing you could use. He only wants one hash, running everything through a Dom parse, will only cause troubles, cause as soon as the HTML is not valid, it will go super mad. You use DOM when you want to more than just fetching a hash, but in this case using regex is easily the best choice you have. |