Firestarter Posted January 13, 2007 Share Posted January 13, 2007 I want to find a string of text then print out the text after it.This is what i'm using now } elseif (preg_match('/CustName\:\s+([^\n]+)/i',$string,$matches)) {It finds a line that begins with CustName: and grabs the text after that ending at the end of the line.But now I have to find a line that begins with </pre><pre><b>role</b>: and do the same thing but with all the special characters in there i'm lost and can't figure it out. And help would be greatly appreciated. Quote Link to comment Share on other sites More sharing options...
c4onastick Posted January 13, 2007 Share Posted January 13, 2007 You're on the right track, a few things:[code]preg_match('/^CustName:\s*(.+)/', $string, $match);[/code]The colon isn't a metacharacter so you don't need to escape it. As long as you don't use the 's' modifier the dot metacharacter can't match a newline (\n), so you can get away with using the dot in a greedy fashion.Post some sample data. But from what it sounds like you're describing you may want something like this:[code]preg_match_all('/^(\w+):\s*(.+)/m', $string, $matches, PREG_SET_ORDER);[/code]This will pull out all the little "label: text text text" pairs. Quote Link to comment Share on other sites More sharing options...
Firestarter Posted January 14, 2007 Author Share Posted January 14, 2007 Here is my code http://sftp.biz/scripts/whois/index.txt you can use it by going to http://sftp.biz/scripts/whois/index.php this script locates the owner of and ip address. It does a pretty good job. Thanks for your help. But the only thing I have trouble is ripe.net one of the sites that it uses to get whois info has way too many variables to allow it to get the right info so I added some extra code. If you have any ideas how I can improve it input is greatly appreciated. Quote Link to comment Share on other sites More sharing options...
c4onastick Posted January 14, 2007 Share Posted January 14, 2007 Looks good, and works good too! I usually use cURL for doing things of this nature, its more robust. http://www.php.net/manual/en/ref.curl.phpIntegrating curl into your script may give you some additional flexibility down the road. Quote Link to comment Share on other sites More sharing options...
Firestarter Posted January 15, 2007 Author Share Posted January 15, 2007 Thanks it's going pretty good just have to keep testing it. I use it mostly as a plugin for another script located below. But it's great for checking ips in my web site logs and email headers.[img]http://sftp.biz/scripts/counter/image.php?site=test&show=counter[/img] Quote Link to comment Share on other sites More sharing options...
Firestarter Posted January 17, 2007 Author Share Posted January 17, 2007 Is it possible to use a preg_match but if the match contains a certain word just ignore it. I have some code below but would like it to just continue searching for matches if what it finds contains a word. Thank you[code] preg_match('/org-name:\s*(.+)/',$ripedata,$matches); if ($matches[1] == "")preg_match('/role\<\/b\>:\s*(.+)/',$ripedata,$matches); if ($matches[1] == "")preg_match('/descr:\s*(.+)/',$ripedata,$matches); $isp = $matches[1];[/code] Quote Link to comment Share on other sites More sharing options...
effigy Posted January 17, 2007 Share Posted January 17, 2007 Can you give an example? Quote Link to comment Share on other sites More sharing options...
Firestarter Posted January 18, 2007 Author Share Posted January 18, 2007 I would like to use the preg_match('/role\<\/b\>:\s*(.+)/',$ripedata,$matches); command and if it finds a word say hostmaster it would skip it and not return a match. Quote Link to comment Share on other sites More sharing options...
effigy Posted January 18, 2007 Share Posted January 18, 2007 Use a negative lookahead: [tt]%role\</b\>:\s*(?!hostmaster)(.+)%[/tt] Quote Link to comment Share on other sites More sharing options...
Firestarter Posted January 18, 2007 Author Share Posted January 18, 2007 Thanks for pointing me in te right direction. I used preg_match('%/role\</b\>:\s*(?!hostmaster)(.+)/%',$string,$matches); Worked great. Quote Link to comment Share on other sites More sharing options...
effigy Posted January 18, 2007 Share Posted January 18, 2007 You're not matching forward slashes on the ends are you? I used the percent sign as a delimiter to avoid escaping forward slashes; therefore, you do not need the slashes by the percent signs unless you're really matching them. Delimiters are flexible in PCRE. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.