Member Log In
Site Navigation
Latest Modifications
- [vB 3.8.4] THX - Hack for VB. 3.8.4
By: bluedog - [vB 3.8.4] Cyb - Chatbox V.2.3
By: bluedog - [vB 4.0.x] PHPKD - Advanced Quick...
By: PHPKD - [vB 3.6.x] StopSpam
By: flappi282 - [vB 3.8.x] vBulletin Chat Addon for...
By: 123flashchat
Latest Template Mods
- [vB 4.0.x] Remove My Profile Link...
By: Ak Worm - [vB 3.8.x] Images DownloadBox...
By: cRs!MP - [vB 3.8.x] Adviertise Mod On Forum...
By: MG4 - [vB 3.8.4] Images PassWordBox...
By: cRs!MP - [vB 3.8.4] Footer Follow Ups
By: Ak Worm
Latest Styles
- [vB 4.0.x] 4.0.3 - VB4STYLE-TWEETA...
By: Belon - [vB 4.0.x] [4.0.3] vbdesigns.de...
By: Belon - [vB 3.8.4] CompletevB - Skylight
By: DreadKnight - [vB 3.8.3] [vB 3.8.4] Barcelona...
By: hoiquantinhoc.com - [vB 3.8.3] Natures Walk by vBSkin...
By: Chri5
Latest Graphics
- [vB ] [anim.]Team Ranks
By: cRs!MP - [vB ] Abstract Circles (3...
By: cRs!MP - [vB ] PlayStation Rank Images
By: cRs!MP - [vB 3.6.12] Heavy Stroked Button...
By: Shelley - [vB ] Minature Ranks.
By: Shelley
vBulletin Modifications »
General vBulletin Section »
vBulletin Modification Tutorials »
[How-To] php: fetch specific info from remote + intro to regexp
![]() |
| | #1 | |||||||||
Location: Israel Age: 29 ![]() |
Status: Offline [How-To] php: fetch specific info from remote + intro to regexp in this tutorial i'll explain basic approach on ways to process via php code info that is located on remote server. this could be quite useful when trying to fetch cover picture or specific text data from a certain website with same pattern. we'll implant this using regular epression pattern matching to your query. (could be for example covers from imdb / gamespot / tv or anything that comes to your mind). small disclaimer before we continue: i'll remind you this tutorial is for educational purpose only. you should be aware that most websites content (either text or pictures) are copyrighted by law, and using this info without owner permission is usually forbidden by law ! so in this tutorial i'm assuming you have proper permisisions. ok, lets start: first i'll introduce you with basic code/"algo" (one solution, of many possible) that will allow you to remote open file & process it line by line: PHP Code: now we'll try to make some regular expression "crash course" to pick up with basics: 1. read tutorials & info guides @ http://www.regular-expressions.info/ (this is very good website with good regexp resources) 2. very common regexp chars/symbols & examples to clear it: ^ - char that match for start of string $ - char that match for end of string . (or .* with repetition) - all chars except for line break [] - range or chars list () - refer to match found later on (see examples) {} - amount of repetition examples: end/start/all chars examples ^a.* - all sentence that start with letter "a" ^a.*t$ - all sentence that start with letter "a" & ends with t use \ (backslash) to "escape" any special char used in regexp, in case you need it. range & repetition examples [0-9] - number between 0-9 [a-z] - lower case letter from a-z [a-zA-Z] - lower & upper case letter (a to z) [0-9]{1,6} - any number with 0-9 digits that can be 1-6 digits long [4-9]{5} - match for 5 digits number (4-9 digits) escaping chars example: \(hello\) - will match for "(hello)" (without the quotes) using () example: when u expect 1 string to match several queries, use () to seperate each result. the later on when using php function like eregi(), each () will be new array field assigned to your dump var. 3. putting it all togther: lets assume i'm looking to extract from html code line like: HTML Code: <a name="poster" href="photogallery" title="The Matrix"><img border="0" alt="The Matrix" title="The Matrix" src="http://ia.imdb.com/media/imdb/01/I/38/48/31m.jpg" height="140" width="99"></a> lets assume i want to extract from it the picture cover link, so a possible match line for this would be something like this: PHP Code: logic says the name could vary, so any copy of "The Matrix" was replaced with .* to match any chars (including space) for the info i need fetching i added () around it (the url itself). notice i've escaped some special chars like / (slash) and . (dot). and notice the usage of numbers range. also note the more accurate the regexp is, the better & certain you'll get what you need. as for the above html-code-line the next regexp could be as well: PHP Code: if we are back to our code example in the begining of this tutorial: PHP Code: also note regarding eregi()/ereg() function i've mentioned in previous lines above. if there are more than 1 match and assuming you did multi () to gather each match wanted, each match will be returned as new array cell, in the order placed on pattern. note that first match starts with cell #1. cell #0 = entire sentence, assuming something matched on your pattern. also few pointers for those hard to match stuff: in case you need to match line with nothing "specail" about it (just plain text), you can't use .* approach, as it will match every line. instead try to use some var as "flag", from previous line. for example if i have 2 lines of html code: HTML Code: name: any text goes here PHP Code: PHP Code: another tip onced passed to me by ShavedApe (which is a great coder) is to use app like "regexbuddy" - though it's not freeware, it's very handy tool that can show you any regexp highlight matching in your text, making your life much easier when much complex regexp is required. hope you find this usefull. :classic: greets. Regards, Idan. * Support will only be given via forums ! * If this post solved/aided your problem, please click "mark as aid" / "mark as solution" as explained in here | |||||||||
|
| | #2 |
| |
Status: Offline interesting, thanks |
|
| | #3 |
| |
Status: Offline Nice tutorial, it explains the basics very well |
|
| | #4 | |||||||||
Location: Anaheim Age: 22 ![]() |
Status: Offline great tutorial Support will only be offered through forums Michael Biddle / vBHackers.comvBSEO 3.3.0 Gold Released with New "Virtual HTML Display" Feature Available for download now vBSEO Google Sitemap Generator - Version 2.5 Released Crawlability Network: vBulletin SEO | vBulletin Hackers | |||||||||
|
![]() |
« Integrating AJAX Technology Into Your Modifications
|
[How To] Display noavatar.gif on the memberlist »
| Thread Tools | |
| |
All times are GMT. The time now is 05:19 AM.
Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.
























