Jump to content

.josh

Staff Alumni
  • Posts

    14,780
  • Joined

  • Last visited

  • Days Won

    43

Everything posted by .josh

  1. based on the value, I'd put my chips on an a/b or mv test... quick, everybody click on the link and fuck up their test numbers!
  2. I don't get it.
  3. Okay look, here is a piece of regex that will match "Box 12" and not match "1555 pine box elder rd" .*box(?!\s+[0-9]+$).* This does not match anything before "box" nor does it match other valid (or non, depending on which way you wanna go) formats. The problem is that with regex, you must regard what it is used for. You cannot write a valid regular expression unless you properly scope out the purpose of it. You can't just say "make it do this regardless of what I want it for" because you have to know what you want it for in order to make it work proper. Asking for things like this, and us helping you like this, is not helpful. We know what you want it for. You want to be able to only send to some 3rd party, addresses that are not po box addresses. Please for the love of God and country, stop making this harder on yourself than it needs to be. Or else, please give more explanation as to why you refuse to take the advice given and insist on trying to bandaid up a regex that is not going to work anyway! edit: Actually I had that backwards: .*box(?!\s+[0-9]+$).* will match "1555 pine box elder rd" .*box(?=\s+[0-9]+$).* will match "box 12" It doesn't really matter which you use, just have to reverse condition. But that doesn't take away from the additional statements I made, though maybe it sheds light on what your problem is to begin with: I think you're basically trying to match a negative. Matching for the absence of something is much harder to do in the regex world. Even where possible, it is a lot harder to read/understand the regex involved, and is completely unnecessary, as all you have to do is reverse the condition it is in. But again, your regex does not account for all (in)valid po box formats. Worse, it actually (dis)allows (in)valid po box formats because overall it is poorly written.
  4. You say you want to only post addresses to a 3rd party that are not po box addresses. The solution is to use an established regex for matching valid po boxes and toss them out if they match, and send the ones that don't match. This is exactly what you are trying to do, only you are insisting on reinventing the wheel with your own regex, which is failing for many reasons, some of which have already been pointed out to you. Honestly I don't really know how more I can help you, except to tell you to reread the advice already given.
  5. Scooby, either a "PO Box" address is valid or it is not. There's no in-between... if the US Post office receives a letter with an invalid formatted address, it's going to be returned to sender. The best you can do is compare to what is valid and toss it if it is valid, and assume keep it if it is not a validly formatted PO Box format. In the 3 examples you listed: 1555 box elder rd ** does not match and that's what we want 1555 pine box elder rd ** should not match but does because of the p in "pine" 45 W North Rd Box 12 ** want to match "Box 12" All 3 of those are valid non-"po box" address formats.
  6. did you even look at the code example?
  7. Friend, you are making this harder than it needs to be. PO Box matching is a common thing that many others have already tackled and figured out, no need to reinvent the wheel. If you are trying to filter out all po box type addresses, you would still use the same po box validation regexes... if (is valid po box regex) { // throw it out } else { // "good" address, do something }
  8. you cannot do this.
  9. Depending on your php.ini settings you may be able to increase your max execution time with set_time_limit(). You may have to change it directly in php.ini though, depending on your settings. But I would really fine-tooth your code first to make sure that it's doing what it is supposed to be doing, and just taking a long time. For instance, you could be maxing the time because of an infinite loop or something...so on that note, I would start there. Look at your loops. Look at the variable(s) used in the conditions. echo out the variables, see if they are changing value as expected, etc...
  10. If you are looking for a way for visitors to easily auto-fill a form on your site based on a local file, you can make a "step 1" or "first form field" be a file input field for the visitor to upload the file. Have it post with ajax and then use server-side script to parse the file and send back the form field values and pop the form field values. This will keep the visitor on the same form page with minimal effort on their end. That's really the best you can do, other than what nogray mentioned (which is not something you wanna do). It is a security feature/limitation; servers shouldn't be allowed to grab arbitrary stuff off a client's computer. The only client storage the server has access to are cookie files for reading/writing cookies. And even then it's not direct access. HTML5 does promise expanded client-side storage abilities, but a) considering peoples' paranoia about cookies, who knows if it will ever really happen b) it still wouldn't be access to arbitrary files on the clients.
  11. to add to xyph's post, with that i modifier, most of the char classes are pointless also, having a range of exactly 1 is pointless. also, that negative lookahead is mostly pointless since you expect spaces next anyways. also, you have a lot of stuff grouped individually with the 0 or 1 quantifier. Since they are not nested, you will get some unexpected matches. also, based on your regex, it looks like you are missing a lot of valid "post office box" formats. also, your match alls will give you unexpected matches. I suggest you google "valid po box formats". There's a lot of info about what is and is not valid, and I even saw some regexes show up in results. Unless there are only specific formats you are wanting to allow, then please list all format examples of what you want to allow.
  12. based on that link you provided, my guess is you tried to use / as the delimiter and then didn't escape it, since you use it in your actual pattern. preg_match can use pretty much any non-alphanumeric character as the delimiter, but whatever you choose must be escaped if you need to use it in the actual pattern.
  13. if (preg_match("~^(http|ftp)://~i", $v["image_path"]))
  14. .josh

    Preg Replace

    no, it's a negative look-behind. It checks to see if the character it is looking for isn't at the start of the string, by looking at the character that comes before it (the ^ signifies start of string, which isn't an actual character, but you get the idea). Otherwise, you will end up with for instance "Abc" to " Abc"
  15. .josh

    Preg Replace

    $string = "abc123AbcDef"; $string = preg_replace('~(?<!^)([A-Z]|[0-9]+)~',' $1',$string); output: abc 123 Abc Def
  16. nothing wrong with your code? well then, I guess you must have a lot of constants defined...
  17. If you are looking to get hired as an employee somewhere (as opposed to freelancing/contract work), employers still very much care about that piece of paper, and you will most certainly be able to get your foot in the door with it, depending on how silver-tongued you are. Now, whether you can keep afloat is another story... Alternatively if you can provide an awesome portfolio of work you've done, and good references (business references, like from clients), then some employers might be willing to overlook a lack of degree in something. It would help if you try to get them to try you out as a freelancer first. But if you are looking to just do freelance/contract work, unless you are actually learning something, you are wasting your time and money.
  18. in your OP code: <?php echo "<ul id='profileMenu'> <li id='firstTab'>" . (isset($tabName=='about-me') ? class='current' : '') . "</li> </ul>"; ?> 1) Looks like your ternary is supposed to add something inside your opening "li" tag but you closed it before the ternary 2) isset syntax is wrong. isset takes variables for arguments, not expressions. 3) Did not wrap quotes around the strings you are trying to add to the "li" tag 4) Did not properly wrap the ternary in parenthesis Here is what the code should look like <?php echo "<ul id='profileMenu'> <li id='firstTab'" . ((isset($tabName)&&$tabName=='about-me') ? " class='current'" : '') . "></li> </ul>"; ?> Couple notes/opinions/suggestions: 1) Issues like this won't happen if you separate your logic from your content. Put that ternary in a variable before the echo and then include the variable in the echo. 2) If you want to echo things multi-line like that, you might wanna look into using heredoc syntax. This will only really work out for you if you follow suggestion #1.
  19. thx all
  20. to clarify, the function expects a delimiter for the pattern, a designated character at the start and end of the pattern. This is because modifiers are also placed inside the string (after the ending delimiter). You can use most any non-alphanumeric character as the delimiter, but whatever you choose has to be escaped if you want to use it in the actual pattern. So for example, in your OP you have / as the delimiter, but wanted to use that character in your pattern. So you could have kept / as the delimiter and just escaped the / in your pattern by doing \/ I personally like using ~ because it rarely comes up in patterns and I hate escaping. But just sayin'... Also, I would also like to point out that you don't actually need to use regex for this..you can explode at the /, count the elements exploded (to make sure there are only 3) and then put them in that checkdate.
  21. skip the foreach.. $colour = "D-E-F-G-H-I-J-"; $colours = array_filter(explode('-', $colour)); echo "'" . implode("','", $colours) . "'";
  22. TLG parse_url() accepts an optional 2nd argument to only return the portion you want. Also, parse_str() returns void. You have to specify the array as the 2nd argument. url = "www.youtube.com/watch?v=aHjpOzsQ9YI"; $query = parse_url($url,PHP_URL_QUERY); parse_str($query,$params); echo $params['v'];
  23. php is probably configured to have magic quotes enabled. You can check by using get_magic_quotes_gpc. If it returns true, use stripslashes() to remove it (see the example and user notes in the get_magic_quotes_pgc() entry)
  24. http://forums.phpfreaks.com/index.php?topic=361331.0
×
×
  • 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.