-
Posts
14,780 -
Joined
-
Last visited
-
Days Won
43
Everything posted by .josh
-
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 }
-
-
you cannot do this.
-
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...
-
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.
-
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.
-
ergi depracation error - trying to update to preg_match
.josh replied to simcoweb's topic in Regex Help
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. -
ergi depracation error - trying to update to preg_match
.josh replied to simcoweb's topic in Regex Help
if (preg_match("~^(http|ftp)://~i", $v["image_path"])) -
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"
-
$string = "abc123AbcDef"; $string = preg_replace('~(?<!^)([A-Z]|[0-9]+)~',' $1',$string); output: abc 123 Abc Def
-
nothing wrong with your code? well then, I guess you must have a lot of constants defined...
-
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.
-
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.
-
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.
-
skip the foreach.. $colour = "D-E-F-G-H-I-J-"; $colours = array_filter(explode('-', $colour)); echo "'" . implode("','", $colours) . "'";
-
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'];
-
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)
-
Trying to search returns an error.
.josh replied to Presto-X's topic in PHPFreaks.com Website Feedback
http://forums.phpfreaks.com/index.php?topic=361331.0 -
renfley this is your 2nd thread looking for a way to advertise sale of your domains on phpfreaks. To be clear, we do not allow advertising on our board, with the exception of 1) Offering or asking for freelance services in the freelance forum. 2) Small, unobtrusive message in your sig. Example: make a page on a site you host where you offer your domains, and in your sig you can put something like "I have some domains for sale, click here!"
-
You cannot do this with the ftp commands (except possibly by using file manipulation commands like fopen/fseek/fread through ftp_raw, if permissions allow, which most likely not..also, I'm not entirely sure you can actually use those commands). You will have to retrieve the file as a whole, and then search through it. You may (with proper permissions local and remotely) be able to do it with sockets though with limitations. (Sockets would in theory allow you to run arbitrary shell commands on the remote server, so for instance you could run php remotely and use the file reading functions, or use shell commands). Either way... None of the file reading commands (whether done locally or through a socket allows you to just grab x through y lines unless the lines are by convention all a fixed number of char length (padded if shorter), and then you can use fseek to jump to the line based on $x * $length. If the lines are not fixed length, you will have to either make a loop and just continue until $x (and then break at line $y), or put the file in its entirety into an array (like with file - not advisable unless the filesize is always expected to be relatively small). edit: nevermind looks like you actually can't even use ftp_exec or ftp_raw. ftp_exec only returns a status code or false, no info, so even if the remote server allowed it, it would be useless. ftp_raw only (assuming permissions allow for it) only do raw ftp commands, not php commands!
-
Okay, I know the DOM object is complex and scary at first, so I'll give you some more examples. After that, you are on your own...follow the provided link, RTFM! <?php // example content to parse. You didn't post that part of your script, but you probably got this from a file_get_contents call or something. $content = <<<EOF <html> <head></head> <body> <a href="site/user/36" title="Vinodkumar">Vinodkumar 36</a> <a href="site/user/37" title="Vinodkumar">Vinodkumar 37</a> <a href="site/user/38" title="Vinodkumar">Vinodkumar 38</a> <a href="site/user/39" title="Vinodkumar">Vinodkumar 39</a> <a href="somepage.php">some page</a> </body> </html> EOF; // create a new DOM object $doc = new DOMDocument(); // load the html content to be parsed $doc->loadHTML($content); // get all the anchor tags $links = $doc->getElementsByTagName('a'); // for each anchor tag... foreach ($links as $k => $link) { // output the full, raw link tag. // wrapped in htmlentities() for display purposes $rawTag = $doc->saveXML($link); echo htmlentities($rawTag) . "<br/><br/>"; // output the innerHTML of the link echo "link value : " . $link->nodeValue . "<br/><br/>"; // alternative way to output the innerHTML of the link echo "link value : " . $link->textContent . "<br/><br/>"; // output a specified attribute echo "href : " . $link->getAttribute('href') . "<br/><br/>"; // output all of the attrib='value' in the current link // (first it is put into an associative array for convenience) $link_attributes = array(); foreach($link->attributes as $attribute) { $link_attributes[$attribute->name] = $attribute->value; } echo "<pre>";print_r($link_attributes); echo "</pre>"; echo "<hr>"; } // end foreach anchor tag ?> output: <a href="site/user/36" title="Vinodkumar">Vinodkumar 36</a> link value : Vinodkumar 36 link value : Vinodkumar 36 href : site/user/36 Array ( [href] => site/user/36 [title] => Vinodkumar ) <a href="site/user/37" title="Vinodkumar">Vinodkumar 37</a> link value : Vinodkumar 37 link value : Vinodkumar 37 href : site/user/37 Array ( [href] => site/user/37 [title] => Vinodkumar ) <a href="site/user/38" title="Vinodkumar">Vinodkumar 38</a> link value : Vinodkumar 38 link value : Vinodkumar 38 href : site/user/38 Array ( [href] => site/user/38 [title] => Vinodkumar ) <a href="site/user/39" title="Vinodkumar">Vinodkumar 39</a> link value : Vinodkumar 39 link value : Vinodkumar 39 href : site/user/39 Array ( [href] => site/user/39 [title] => Vinodkumar ) <a href="somepage.php">some page</a> link value : some page link value : some page href : somepage.php Array ( [href] => somepage.php )
-
We actually at one point in time in the past did have a separate "Author" group, where you pretty much just had to be a registered member and ask for it. That was available for like a year and in all that time only like 3 people joined, didn't post anything on the main site, and eventually removed themselves from the Author group. So we just ditched that group. But right now, what you said... that is more or less how the current restrictions effectively are. When a member has been around a while, has x+ posts, and gives decent advice, not being a complete asshat in the community...someone in Guru+ can nominate that member to become a Guru and other Guru+ can vote yay or nay and if the yay's win, they become a Guru, which gives them access to make blogs/tutorials. So...so far IMO there isn't much reason to just give open access to regular members; trying that in the past did not generate the interest we had hoped for, and putting restrictions on it like that..we already do that. IOW my personal vote is to keep it as-is.
-
FYI any guru+ member already has the ability to add a blog or tutorial to main site right now.
-
sowna, judging by the code you posted, it looks like you are working with an html document, perhaps retrieved from a file_get_contents or cURL call, and you are trying to extract the user id from links on the page. When trying to parse html, it is safer to use a DOM Parser than regex. example: // example content to parse. You didn't post that part of your script, but you probably got this from a file_get_contents call or something. $content = <<<EOF <html> <head></head> <body> <a href="site/user/36" title="Vinodkumar">Vinodkumar 36</a> <a href="site/user/37" title="Vinodkumar">Vinodkumar 37</a> <a href="site/user/38" title="Vinodkumar">Vinodkumar 38</a> <a href="site/user/39" title="Vinodkumar">Vinodkumar 39</a> <a href="somepage.php">some page</a> </body> </html> EOF; // create a new DOM object $doc = new DOMDocument(); // load the html content to be parsed $doc->loadHTML($content); // get all the anchor tags $links = $doc->getElementsByTagName('a'); // for each anchor tag... foreach ($links as $link) { // get the href attribute $href = $link->getAttribute('href'); // if href is the right link ... if ( stripos($href,'/user/')!==false ) // user id is the last / delimited value in $href, grab it and put into array of found user ids $user_ids[] = array_pop(explode('/',$href)); } // end foreach anchor tag // example showing output of found user ids echo "<pre>"; print_r($user_ids); echo "</pre>"; output: Array ( [0] => 36 [1] => 37 [2] => 38 [3] => 39 )