Jump to content

.josh

Staff Alumni
  • Posts

    14,780
  • Joined

  • Last visited

  • Days Won

    43

Everything posted by .josh

  1. you can use cURL to get the image or a response.
  2. well he said he tried a urlencoded & and it didn't work. I suspect he's decoding it before parsing it.
  3. This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=351619.0
  4. would help if you show a full example URL and the code you're currently using.
  5. Other than unnecessarily escaping your forward slashes (they mean nothing special in regex, the only time you need to escape them is if you are using them as pattern delimiter, which you are not (you are using "~")), the regex works fine. example: $links = array( "http://www.example.com/news/somearticle1", "http://www.example.com/news/somearticle2/2", "http://www.example.com/news/somearticle3/3", "http://www.example.com/news/somearticle4/44", ); foreach ($links as &$link) { $link = preg_replace('~/?\d*/?$~', '', $link); } print_r($links); output: Array ( [0] => http://www.example.com/news/somearticle [1] => http://www.example.com/news/somearticle2 [2] => http://www.example.com/news/somearticle3 [3] => http://www.example.com/news/somearticle4 ) So your problem is somewhere else in your code. Maybe you are preg_replacing the wrong variable or assigning results to wrong variable (like a typo or something). Maybe later on you use the wrong variable to add new number on. Who knows, I'm just throwing out random guesses since you have no other code posted.
  6. And what about the other ~185 (+/- a few depending on who you ask) independent countries? @TLG: LOL@pic
  7. USA of course. We're holding aliens hostage in area 51, duh.
  8. You asked for a push in the right direction and I explained what more you need to do. If you and your friend "cobbled" that together then you should have enough understanding to read what I wrote and apply it. Was there something in particular you didn't understand in my response? Do you need some clarification on a particular point in my reply? No offense, but I'm not sure what more I can do for you, short of writing the code for you...responding something vague like "I need help" when I gave you the help you asked for to me means what you're *really* asking for is for me to write your code for you, which I'm not going to do, because: 1) This smells like homework. What is the point in taking a class in something if you're just going to c/p and not actually learn anything 2) I'm not here to write your code for you. Unless you wanna pay me, then I will write it for you. This sort of conflicts with the first point but I'm not your dad; if you wanna waste your time in class not learning anything then that's on you.
  9. non-regex on-liner alternative: $string = implode("/",array_slice(explode("/",$string,4),0,3));
  10. This part needs to be modified: document.write(wordsArray[i]+ "<br />") // Output each word to the document and add a line break after each one if(wordsArray[i].indexOf("a") > -1) // Check to see if the word contains a letter a { aWordCount +=1; // If the word contains a letter a, add one to the count } You need to remove the linebreak tag from your document.write so that you can add the letter count next to the word. Or better yet, move your document.write below the code that determines how many instances of "a" are in it, so that you can document.write() everything in one go. Then inside your condition.. You need to either loop through each letter in wordsArray and increment a variable (example: numLetter) each time it matches the letter "a", or use a .match() regex instead of .indexOf() to match for it and count the returned results and put it into numLetter. Also note that you are currently doing a case-sensitive search, so for instance, it will not count the "A" in "Andy". Since you probably want it to be case-insensitive, you will need to first wordsArray.toLowercase() or use the i modifier if you opt for the regex approach. Finally, you will need to actually document.write numLetter after this code (and then add the linebreak tag) so that it will show the result next to the word.
  11. Because I don't know how you are handling the keyword(s) to look for, and how you are looking to handle results, you may need to tweak this to suit your needs...but here is a function to get you started, based on the content you provided. /** * get_ids_by_keyword returns a list of thread IDs based off given keywords * @param string $content is the content to scrape * @param mixed $keyWords is a string (for a single keyword) or an array of * key words to search. * @param bool $pMatch is a flag to determine whether or not to match full * or partial words. Default is full match * @param bool $cs is a flag to determine whether or not search should * be case-sensitive. Default is case-insensitive * return mixed If results found, a multi-dim associative array is returned, * following this format: keyword => (id => instances). * NOTE: if $cs==false, keyword is returned lowercased. * If no keywords were matched, return false. */ function get_ids_by_keyword ($content, $keyWords, $pMatch = false, $cs = false) { if (!is_array($keyWords)) $keyWords = array($keyWords); $keyWords = implode('|', $keyWords); $results = array(); $b = ($pMatch == false) ? '\b' : ''; $c = ($cs == false) ? 'i' : ''; preg_match_all('~<span class="(?:comment)?postername">.*?<span id="no(?:thread|rep)(\d+)">.*?<blockquote>(.*?)</blockquote>~s',$content,$posts); foreach ($posts[2] as $i => $post) { if ( preg_match_all('~'.$b.'('.$keyWords.')'.$b.'~'.$c, $post, $keyWordFound) ) { foreach ($keyWordFound[1] as $kwf) { if ($c) $kwf = strtolower($kwf); $cid = $posts[1][$i]; $results[$kwf][$cid] = ( isset($results[$kwf][$cid]) ) ? ++$results[$kwf][$cid] : 1; } } } return ( count($results)>0 ) ? $results : false; } // end get_ids_by_keyword Basically you call the function passing the content to be scraped, and the keyword(s) you want to look for. It will then return a multi-dim associative array of the keyword(s) found, the post id of the post (including replies to posts) the keyword was found in, and how many instances of the keyword was found in the post. By default the function performs a case-insenstive full word search. There are optional arguments to make it case-sensitive and also return match for partial matches. Example 1: case in-sensitive full word search of 4 words within content of OP example. Notice how "boring" is not returned because the only instance similar within the content is "boringly" but this is flagged as a full word match. $keyWords = array('a','problem','boring','let'); print_r(get_ids_by_keyword($content, $keyWords)); Output Array ( [a] => Array ( [373301167] => 2 [373301334] => 1 ) [problem] => Array ( [373301167] => 1 [373301334] => 1 ) [let] => Array ( [373300183] => 1 ) ) Example 2: case in-sensitive partial word search of same 4 words. Now "boring" is matched because we flag it for partial matches. Also we get a lot of matches on "a" because it found a lot of them within words. $keyWords = array('a','problem','boring','let'); print_r(get_ids_by_keyword($content, $keyWords, true)); Output Array ( [a] => Array ( [373301167] => 9 [373301257] => 1 [373301298] => 3 [373301334] => 6 [373300183] => 2 [373301286] => 1 [373301297] => 1 ) [problem] => Array ( [373301167] => 1 [373301334] => 1 ) [let] => Array ( [373300183] => 1 ) [boring] => Array ( [373300183] => 1 ) ) Example 2: case sensitive partial word search. The first keyword is now capitalized. $keyWords = array('A','problem','boring','let'); print_r(get_ids_by_keyword($content, $keyWords, false, true)); Output: Array ( [problem] => Array ( [373301167] => 1 [373301334] => 1 ) )
  12. @shamuraq a) the most immediate reason your preg_replace didn't work was because you have spaces between the part of your pattern that match for the numbers vs. the /, so it expects for instance "1 / 2" not "1/2". b) supposing your string does have a fraction with spaces in it like "1 / 2" your replacement basically just swaps out the "/" for a "|"...which..why? You said you wanted to mark it up with some html strong... @QuickOldCar: couple things about your regex.. a) since you are matching for a / it would be cleaner to pick a different pattern delimiter so you don't have to escape it in the pattern. b) [..] is a character class. It means to match any one thing inside the bracket. It is good for if you want to match for more than 1 thing like something in a range. For example [a-z0-9] will match any 1 letter or number. Since you are only matching for one thing (a "/"), while it *technically* works, there's no need for a character class. c) Your pattern will only match single-digit fractions. For instance, it will not match 1/10 (it will only match 1/1 part of it). @shamuraq: Here is a pattern for you: $pattern = '~([0-9]+\s?+/\s?[0-9]+)~'; This will capture the entire fraction $1 or \1 for your $replacement variable. This pattern will allow for both "1/2" and "1 / 2". If you only want it to match if no spaces, remove the two "\s?" parts.
  13. Well php is a loosely (weak) typed language...
  14. Installing WordPress isn't all *that* hard if you know what you're doing, and everything you listed I believe is already built-into it or has extensions for it, even multiple authors/blogs (WP used to have a separate multi-author/blog system at mu.wordpress.org but they have since combined it all into one system). It does take a bit more skill to customize it in the way of looks though..if you're looking to do a fully custom implementation. There are a ton of out-of-the-box skins/themes available for free or cheap if you're willing to settle for that though. But is it worth paying someone else $500 for? I know a lot of people who offer WP installs/customizations as part of their services (I know some people who ONLY offer that as a service) and they generally charge $300-$500 to do it, depending on how much customization you want. But I've also seen a lot of people charge a hell of a lot more...usually larger companies will charge more because they deal with larger clients. IMO it is worth the price if you don't want to take the time to learn it and do it yourself. Again, it's not terribly hard to do it if you know what you're doing, but it could quickly become really frustrating if other things prevent you from having a smooth install, like having to tweak/fix other server settings that are otherwise preventing it from going smoothly. But if you are interested in learning web dev stuff then it would probably be better for you to do it yourself; it's as good as any other place to get your feet wet. If you do opt to pay for someone to do it, I would find out if they are offer any kind of training to walk you through the interface, see where/how to do the stuff you want, etc... this may or may not be included in that price, and if you don't opt for that service, you may find yourself spending a fair chunk of time sorting that out, as well.
  15. Well i guess point 1 you arent logged in yet so thats kinda superfluous. Point 2 you wouldnt be either but IMO you should show it on that page. And the others work under logged in status logic so really the only thing is first point.
  16. Yes that makes sense...but isnt the common denominator between all those pages/scenarios that you ARE logged in? Therefore, you can just base the logic on logged in status.
  17. have it show/hide based on logged in status. I assume you have a session var somewhere in there that is only set when user is logged in, yah?
  18. @others: Whether or not it *should* be wiped is not really the point..if that's what doubledee wants to do, that's her prerogative. Though FYI I do agree, it is the de facto standard to not wipe it, even if it's incorrect. @doubledee: yes, that makes things clearer, but as others have said, can't really tell from the snippets of code what is going wrong, you should post complete version.
  19. @doubledee: I was not being sarcastic. My point, which you missed, is that you aren't being very clear about your problem, it is not "spelled out", and I made a "best guess" accordingly, with a prefix of "If this is the case...".
  20. Then IMO you should look into using AJAX. Do you use a framework like jQuery?
  21. I don't understand why you are trying to disable the button...it's the button that allows the user to submit the form, yes? The button sort of has to work in order for the user to submit the form...
  22. It's not posting because you disabled the button. It's like cutting the wires between the switch and battery and then wondering why the lightbulb doesn't light up when you flip the switch... if you're lookin' to post the form w/out refreshing the page, then use ajax.
  23. Admittedly it's somewhat hard for me to understand what you're problem *really* is, since you are using random *labels* to describe your problem and putting them in *stars* instead of actually defining the problem. But I *think* you are saying you only want your form to populate the fields with the user-inputted values if it passes your validation, but your form fields are being populated even when the data does not pass validation? If this is the case, then solely based off the code you have provided, my guess is you have Register Globals turned on. If this is the case, your $_POST['firstName'] is automatically being assigned to $firstName upon form submission.
  24. I don't think the ++ is necessary though...it shouldn't ever backtrack because there's nothing else in the pattern to match for. Also, to 1up you on using something like trim to get rid of the @...can use \K to have the regex engine ditch it: @\K[^:]+
  25. IMO the "guideline" is the marks/comments so that you will improve next time around. Remember, school is a learning process, where you go from suck to not suck. It's not intended to be perfection every round. Also, it is a good thing to an extent to defend your work, but in the real world...you're always going to have a boss who tells you one thing and means another, and "That's not what you said" only goes so far. So, you should take this as a lesson to take it upon yourself to ask questions and get clarification on everything beforehand. Remember, the reason you (will) have the job is because you know the details, not the boss - they don't know any better, so it is up to you to pry that shit out of them. But anyways, yeah I agree as far as commenting. Always err on the side of over-commenting. If it's your own code that only you will ever touch, and you're confident in yourself that your naming conventions are enough for you, that's fine. But in the real world where you're working with lots of other peoples' code and they yours, there's really no such thing as too many comments. Also want to mention that when you comment, you need to comment what your intentions are, what you are expecting to happen. The code reflects the comments, not the other way around. IOW the comments are there to explain in human language what the script is supposed to be doing. For me, my pseudo-code usually turns into my comments. But also, comments are especially important if you're trying to track down a logic bug. The first and most important step to tracking down bugs is to figure out what it's supposed to be doing in the first place, so if you have clearly written comments then you can compare them to the actual code and more easily find those bugs. "Oh hey, it says here that I'm supposed to be doing xyz but the code clearly doesn't do that!" sort of thing.
×
×
  • 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.