Jump to content

dsaba

Members
  • Posts

    724
  • Joined

  • Last visited

    Never

Everything posted by dsaba

  1. Reading about negative lookaheads and postive lookaheads, trying to construct a regex pattern that matches: any string 'this' any string 'that' so it should not match: any string 'this' any string 'this' 'that and it should also not match: any string 'that' any string 'that' 'this' but it can match: any string 'that' any string 'this' so you see it should have the needles 'this' and 'that' but not this or that repeating itself I tried doing this: <?php $pat = '~.(??!(this|that)).)+this(??!(this|that)).)+that.~'; $haystack = 'hello how are you this doing today that maybe whatever this this that should not match, but that okay later this should, but no that of that of this okay?'; preg_match_all($pat, $haystack, $out); print_r($out); ?> but it matches 'whatever this this' when it shouldn't how can I fix it? -thanks Update by effigy: Changed $haystrack to $haystack in the code.
  2. What profanity and abuse are you talking about? I thought you were trying to mimic urlencode on queryStrings in a way with htmlspecialchars, I suggested the best way to mimic url encode on querystrings is of course to use the urlencode() function. Something not working? I have no idea what you mean. It was a suggestion, if you don't want to do it, don't. If you're offended by people's attempts to help you or offer suggestions, then simply do not press that "new thread button." Because suggestions whether you agree with them or not are exactly what you are going to get. If you are going through personal issues with yourself or me, I suggest you be mature and contact me directly about your issue, instead of slandering me on public forums because that is profane.
  3. Charmin because my ass deserves the best, like those bears.
  4. your subject or haystack you are searching for is this string: $subject = "http://images.google.co.uk/images?q=". $str; I suspect $str hold a queryString for a search term you want to search through the contents of that page, not the page url string! try this: $subject = file_get_contents("http://images.google.co.uk/images?q=". $str); when debugging your code, try outputting and validating what your input should be next time, and you can catch something like this on your own, like echo $subject; *edit I also noticed you did this: $str = htmlspecialchars($_POST['str']); if you are trying to mimic a queryString that google sends in the URL I would do: $str = urlencode($_POST['str']);
  5. are you referring to html comments? <!-- html comment -->
  6. post your sample input data, and exact code you use to parse through it however this works fine for me: <?php $str = '<div>hello</div> jkljdsfkljsdff <div>whatever></div> somethign else later <div> lalalal!</div>'; $pat = '~<div>(.*?)</div>~'; preg_match_all($pat, $str, $out); print_r($out); ?> you can add the s modifier if you are parsing or the match is through multiple lines: $pat = '~<div>(.*?)</div>~s';
  7. run my last example like I sugggested, and you will find out. Your browser basically freezes up, its the same type of effect like running an infinite loop. No this is not the equivalent of my above code. Let me explain: setinterval() runs code in time intervals I dont think you can set any time interval small enough to compare to the interval between each iteration in my above do, while loop. So set interval will not achieve the same results. Each iteration of that above while loop should be quicker than milliseconds, you can't go smaller than millisecond intervals with setinterval.
  8. here is the root of the problem: <html> <body> <script type="text/javascript"> var now = new Date().getTime(); var endTime = now + ((1000*60)*2); //2 minutes after now while (now <= endTime) { var seconds = (endTime - now)/1000; //document.write("seconds left: " + seconds); //document.write("<br>"); now = new Date().getTime(); } document.write("done"); </script> </body> </html> you can run the above code with the write statements commented, or with them uncommented and it will still lag is it impossible to run a while loop until a certain time has elasped without lag? yes i'm aware of setinterval and setimout, but these are different things, the above code should still be possible as it is not an infinite loop
  9. Here is my getResults.html page: the getResults(maxMins) function is the important part... <html> <head> <script type="text/javascript"> function GetXmlHttpObject() { var xmlHttp=false; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; } function getResults(maxMins) { //make ajaxObj ajaxObj=GetXmlHttpObject(); if (ajaxObj) { //initiate countdown display //run code until time ran out var endTime = (new Date().getTime()) + ((1000 * 60) * maxMins); var numResults = 0; //request results via ajax ajaxObj.open("GET","random_numbers.php",true); ajaxObj.send(null); //loop do { if (ajaxObj.readyState==4) { numResults = numResults + (ajaxObj.responseText); //alert(numResults); var resultStr = "Found " + numResults + " results."; document.getElementById("resultsDiv").innerHTML = resultStr; //request results via ajax ajaxObj.open("GET","random_numbers.php",true); ajaxObj.send(null); } } while ((new Date().getTime()) < endTime) //spit out total results found document.getElementById("resultsDiv").innerHTML = "Time's up.<br>Found " + numResults + " total results"; } else { alert("Your browser does not support ajax!"); } } </script> </head> <body> <form name="formExamp"> Max minutes:<input type="text" name="maxMins" value="1"><br> <input type="button" onclick="getResults(document.formExamp.maxMins.value);" value="Start!"> <div id="timerDiv"></div><br> <div id="resultsDiv"></div><br> </form> </body> </html> here's my random_numbers.php page: <?php header("Cache-Control: no-cache, must-revalidate"); // Date in the past header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); echo rand(0,20); ?> The problem is when I press the button start and it starts requesting the php page via ajax in a do while loop, it lags the whole page up. What i'm trying to do is to loop to continue requesting the random_numbers.php page and adding up the results and outputting the results for 2 minutes. So there is no set amount of times the random_numbers.php page can be requested and iterated, teh control for the loop is the time and it should ONLY request the page again once the last ajax request has been completed. Yet.. it still lags. Any way to achieve the same results without the lag? How can I fix my getResults() function ?? Thanks *edit maybe someone should move this to ajax section.. I though it was more of a JS problem though.. with the loop and the lag.
  10. is it possible to load an empty xml string or something and then just add attributes with simplexml.. will this work?
  11. I read about editing/changing an already existing xml document with add attributes and add childs functions in the simplexml library in php. However is it possible to create an xml file from scratch and add nodes..attributes..etc.. with simplexml??
  12. Yes bacon too, you didn't get me. Not everybody is in love with bacon.
  13. I think correct hungarian notation is each new word is capitalized like $TotalCustomers but I always prefer the first word in the variable to not be capitalized like: $totalCustomers
  14. What's any pet peeve you have related to programming?
  15. What's wrong with all of you? Too much of anything is not good. Period. Go outside, there is a world you are missing out on and i'm not just talking about sunlight. I don't really know the point of this thread, I mean the majority of replies you are going to get are those who do the same thing you are doing, and can only sympathize with you. Is that what you wanted? And the healthy answer is obvious. This is phpfreaks forum. The people who come here are either crazy about php or crazy because of php, or both. What would have been interesting rather is if you made this a poll on those who do similar things like what you are describing.
  16. Well, unless you want to pay a freelancer to do it for you, you're going to have to teach yourself some things about php, to get this done. see these functions for getting done what you want: http://us.php.net/str_replace (non regex solution) http://us.php.net/manual/en/function.preg-replace.php (regex solution) here's a simple example using parallel arrays and str_replace, it all depends on what and how you want to do what you're doing... if you have problems coming up with algorithim, post some sample input data and output data of how you want it, this is the best explanation you can give <?php $words_en = array('hello', 'see you later', 'welcome'); $words_es = array('hola', 'hasta luego', 'bienvenidos'); $str = 'hello welcome to my house, see you later!'; echo $str; foreach ($words_en as $k => $enWord) { $esWord = $words_es[$k]; $str = str_replace($enWord, $esWord, $str); } echo $str; ?> good luck
  17. if there is going to be any bug, its going to be because of something in your code, or a bug within a function like fwrite().. etc.. so post your problem code
  18. I"m not familiar with "skipping" files.. I don't know if this is true. I do know that there is a timeout limit in php which you can set in your php.ini file, big files will probably take a long time to download, you could try using ajax to send many requests to the php script on the server, so it won't time out
  19. yeah learn to explain better... if you set a cookie, you cannot instantaneosly echo it afterwards, you can only echo it after another page load, so it can properly read the cookie you just wrote cookies aren't ajax and are not asynchronous, they are injected & included in your header, which changes every page load, so if you have a header with no cookie and then create a cookie on that page load which had just loaded with no cookie, how can you expect to access the cookie? you can't! you can only access cookies that have been stated in the header..etc.. short story, set the cookie in a previous page load, so when it comes time to use it, you can use it or if you want to instantaneously use it, refer to the value you just assigned to the cookie, rather than trying to call the cookie immediately
  20. Speed aside....... Once a user closes the browser the "session" in the user's eyes is lost, deleted, expired.. But physically in the the session that resides on the server, the cookie file, does it get deleted instantaneously as well? If so, this is certainly interesting as how the server knows when to delete the file or session. And if this does happen instantaneously, this certainly is an advantage over a db approach because with a DB you guess or give a user so many minutes before you deem him inactive if he doesnt refresh the page. I record active users within 2 minutes, if there is no activity from users in 2 minutes, then I deem them inactive. If a session file on the server gets deleted instantaneously, then surely it will be more precise in counting users that are active than a DB approach could. Although, a DB approach can yield more information than just # of users online, but also things like last visited..frequency..and users in the last so many minutes..
  21. get some fonts for barcodes here: http://freebarcodefonts.dobsonsw.com/ learn how to write text on images using your supplied fonts: http://us2.php.net/manual/en/function.imagefttext.php (freetype, opentype fonts) http://us2.php.net/manual/en/function.imagettftext.php (truetype fonts) concept: you are creating images (jpeg,png, gif) on the fly with the GD library an associated functions in PHP 1. create blank image 2. write text on image with barcode font there are many tutorials on how to create sample images on google and internet, but writing text on images is quite simple out of all gd uses
  22. I tried it verbatim as you first suggested and it didn't work, then I added the extra parenthesis. Still didn't work. Now I tried this: $pat = '~: \<strong\>([0-9,]+?)\</strong\> \(([0-9\.]+?) .~'; Doesn't work either. So then I tried this: (took the question marks out) $pat = '~: \<strong\>([0-9,]+)\</strong\> \(([0-9\.]+) .~'; also didn't work
  23. Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) ) That's my result with that change, even after I fixed the extra ) parenthesis you forgot to add. I tried: $pat = '~<strong>([0-9,]+)</strong> \(([0-9\.]+)\)~';
  24. (yes that's the most descriptive title I could come up with, other than "regex help") haystack 1: <?php $haystack = '<td class="panelsurround" align="center"> <div class="panel"> <div align="right"> <div class="fieldset"> <div style="padding:3px"> תאריך הצטרפות: <strong>04-28-2007</strong> </div> </div> <fieldset class="fieldset"> <legend>הודעות</legend> <table cellpadding="0" cellspacing="3" border="0"> <tr> <td> סך הכל הודעות: <strong>3,117</strong> (13.63 הודעות בכל יום) </td> </tr> <tr> <td><a href="search.php?do=finduser&u=3095" rel="nofollow">מצא את כל ההודעות על ידי ThaiB0X</a></td> </tr> <tr> <td><a href="search.php?do=process&showposts=0&starteronly=1&exactname=1&searchuser=ThaiB0X" rel="nofollow">מצא את כל הנושאים שנכתבו על ידי ThaiB0X</a></td> </tr> </table> </fieldset>'; ?> *edit haystack 1 is encoded in utf-8, the language is hebrew, but the codebox converts it to html entities so i'm putting it in the quotebox instead: haystack 2: <?php $haystack = '<tr> <td class="tcat" width="50%">Around the world</td> <td class="tcat" width="50%">Bla bla bla</td></tr><tr valign="top"> <td class="panelsurround" align="center"> <div class="panel"> <div align="left"> <div class="fieldset"> <div style="padding:3px"> Coffee Donuts: <strong>06 Jan 2002</strong> </div> </div> <fieldset class="fieldset"> <legend>Books</legend> <table cellpadding="0" cellspacing="3" border="0"> <tr> <td> Cheap Electronics: <strong>15,300</strong> (7.06 scratch your head) </td> </tr> <tr> <td><a href="url" rel="nofollow">Sunshine is good for the body</a></td> </tr> <tr> <td><a href="url.php/whatever/ok.php" rel="nofollow">The great corral reef is in Australia</a></td> </tr> </table> </fieldset>'; ?> <?php $pat = '/\<td\>[ ]+?[^ ].+: \<strong\>([0-9,]+?)\<\/strong\> \(([0-9\.]+?)[ ].+?\)[ ]+?\<\/td\>/'; preg_match_all($pat, $haystack, $out); print_r($out); ?> the two substrings that I would like to match are shown in this simplified example below, the substrings I want to match are enclosed in { } brackets The actual haystrack though does not have these brackets <td> סך הכל הודעות: <strong>{3,116}</strong> ({13.63} הודעות בכל יום) </td> The haystacks will be encoded in utf-8. Can you fix my regex code, or tell me what i'm doing wrong?? My above regex comes up with no matches at all. - Thank you.
  25. try this: <?php $phoneNumber = "Curtis Hunter"; $message = "6151851"; $curlPost = 'username=' . urlencode($phoneNumber) . '&password=' . urlencode($message) . '&submit=login'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://www.warptweet.com/login.php'); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost); $out = curl_exec($ch); curl_close($ch); echo $out; ?>
×
×
  • 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.