-
Posts
14,780 -
Joined
-
Last visited
-
Days Won
43
Everything posted by .josh
-
$bad_stuff = ("'",'"','%27','SELECT','INSERT','script'); $input = "input from user"; foreach ($bad_stuff as $bad) { if (stripos($input, $bad) !== 0) { // bad item found, do something } }
-
Replace Each Instance of a substring with values from an array.
.josh replied to proggR's topic in PHP Coding Help
vsprintf should do the trick Good for if you have established positions of array values... $query = "SELECT * FROM users WHERE user_name = '%s' AND user_role = '%s'"; $query = vsprintf($query,array('name','role')); echo $query; If you need something more complex, for example, arbitrarily positioned values in the array, you can do something like this: $query = "SELECT * FROM users WHERE user_name = '%2\$s' AND user_role = '%1\$s'"; $query = vsprintf($query,array('role','name')); echo $query; Notice how the array has the values listed backwards, and in the query string, I'm specifying array elements (note: this acts more like regex's captured groups, starting at 1, not 0) -
different browsers render what you put differently. For instance, it could shorten it to '#eee' or do it as rgb(value,value,value), or '#eeeeee' or 'eeeeee'. Try adding the following to your loop (not inside the condition): alert(document.getElementById('answer'+i).style.backgroundColor); look at what the value actually is (and compare in different browsers and versions that you are coding for).
-
Your posted regex can't make what you are saying it's making. You have: (?<!href=")(https?://[A-Za-z0-9+\-=._/*(),@\'$:;&!?%]+) This pattern says to match (https?://[A-Za-z0-9+\-=._/*(),@\'$:;&!?%]+) if it is not preceded by href=". So if you have... [link href="http://www.mycoolsite.com/" target="_blank"]http://www.mycoolsite.com/[/link] ...the http://www.mycoolsite.com/ in your [link] tag won't match, because it is preceded by href=" The only way you could be getting the output you say you are getting is if you are doing something more than this preg_replace(), and have not posted everything you are actually doing here. However, I do see a flaw in what you have posted: test: $str = "http://www.mycoolsite.com/"; $str = preg_replace('|(?<!href=")(https?://[A-Za-z0-9+\-=._/*(),@\'$:;&!?%]+)|i','[link href="$1" target="_blank"]$1[/link]', $str); echo "round 1 : " . $str . "<br/>"; $str = preg_replace('|(?<!href=")(https?://[A-Za-z0-9+\-=._/*(),@\'$:;&!?%]+)|i','[link href="$1" target="_blank"]$1[/link]', $str); echo "round 2 : " . $str . "<br/>"; $str = preg_replace('|(?<!href=")(https?://[A-Za-z0-9+\-=._/*(),@\'$:;&!?%]+)|i','[link href="$1" target="_blank"]$1[/link]', $str); echo "round 3 : " . $str . "<br/>"; output: round 1 : [link href="http://www.mycoolsite.com/" target="_blank"]http://www.mycoolsite.com/[/link] round 2 : [link href="http://www.mycoolsite.com/" target="_blank"][link href="http://www.mycoolsite.com/" target="_blank"]http://www.mycoolsite.com/[/link][/link] round 3 : [link href="http://www.mycoolsite.com/" target="_blank"][link href="http://www.mycoolsite.com/" target="_blank"][link href="http://www.mycoolsite.com/" target="_blank"]http://www.mycoolsite.com/[/link][/link][/link] So I do see a flaw..but not what you are saying. I see matching and replacing the original link inside the tag, not inside your [link..] tag. This should solve that... $str = preg_replace('~(?<!link href="|\])(https?://[A-Za-z0-9+\-=._/*(),@\'$:;&!?%]+)~i','[link href="$1" target="_blank"]$1[/link]', $str); p.s. - I changed your pattern delimiter from | to ~ you should not use | as the pattern delimiter because it has special meaning in regex (it is the "or" operator). While it is possible to use | as the delimiter, it makes it very difficult to then use it as the "or" operator in the pattern.
-
To clarify, the phpfreaks SMF board is broken down into several forums. "PHPFreaks.com Questions, Comments, & Suggestions" is one forum on the board. This forum is not for asking php/coding questions, it's for asking questions about the forums/board/site/community itself (read the stickies in this forum). If you ask your question in this forum, it will be moved or removed and you may or may not get a thonging out of it. However, there are lots of other forums on this board where you can ask coding questions.
-
I lied. I actually used print up until about 5m ago when I read salathe prefers echo. So I chose echo because I'm totally stalking salathe.
-
I grew up with print as well. Having said that, I prefer echo for no particular reason.
-
As a security measure, you cannot do this with Javascript. The only thing on your machine Javascript is allowed to read are cookies from the browser's cookie file, based on the domain of the requested page. In order to do something like this, you will need to write a browser plugin or ActiveX control to act as a proxy between the file and javascript - something the user will have to specifically install or allow to run in the browser.
-
Are there any native network functions in Javascript?
.josh replied to FalseProphet's topic in Javascript Help
afaik there is not. -
-
I think your problem is probably the browser caching the image. Only way to really keep it from doing that is attaching a random number to the request, like <img src="pic.php?n=123"> usually people just do something like this: <img src="pic.php?n=<?php echo time(); ?>"> which just uses the current unix timestamp as the number. ...but you said you can't change index.html. Well..I'm afraid you're out of luck then. Image caching happens in the browser, so you're going to have to change index.html like above or have a meta tag or something specifically telling the browser not to use cached images.
-
guys, he's asking about generating passwords, not validating them. OP: I'm confused, you refer to "oh" and "el" as letters... so when you say you do not want it to contain "oh" or "el" do you mean 1) 2 literal 2-character strings? Like.. ohxxxxxx <-bad oxxxxxxx <-good hxxxxxxx <-good oxhxxxxx <-good elxxxxxx <-bad exlxxxxx <-good exxxxxxx <-good lxxxxxxx <-good 1) Or, were you just "pronouncing" them, and you really meant "o" and "l", like... xxxxxxxx <- good oxxxxxxx <- bad hxxxxxxx <- good exxxxxxx <- good lxxxxxxx <- bad if the answer is #2 (which I'm guessing that's what you meant...) $password_length = 8; $pool = array_merge(range('a','k'),range('m','n'),range('p','z'),range(2,9)); shuffle ($pool); $password = implode('', array_slice($pool,0,$password_length));
-
Got a Twitt0rrr Idea -> Possible? and Is It Hard to Do?
.josh replied to chaseman's topic in Miscellaneous
To recursively farm for people to spam, obviously. -
make sure to put in your .htaccess file to mark it as permanent 301 redirect so that the search engines don't write you off as trying to dupe content.
-
Okay, so you are trying to post copyrighted material. That is not acceptable. Also, I just deleted a yii thread of yours, where you advertised yii. And yes you did advertise it because in a followup post, you felt necessary to correct someone that you were not spamming, but advertising (which is the same thing btw). If you are not aware of the rules, then You should not even be a registered member, as reading the ToS is a requirement of registering. Yeah yeah I know nobody really reads that stuff but that's not an excuse. I suggest you go and read the rules now. There is a link in the menu, as well as right above every single Post button.
-
Yes, what is this pdf you are trying to post? If you are trying to post copyrighted or illegal content, or promote something (spam/advertising), that's a ticket to banville.
-
SEO? ewww...go wash yourself thoroughly before coming back here.
-
I haven't fully looked at it but at first glance, your issue is probably because you are using greedy quantifiers instead of lazy quantifiers. Use .+? instead of .+
-
If you are using php 5.3+ You can just use strstr $user = strstr($email, '@', true);
-
Also those aren't errors they are warnings.
-
Yep, trim() is definitely the better route. However, to answer your question about preg_replace()... $str = ' --- ----- ------f-oo-oo----'; $str = preg_replace('/^(-|\s)+-(.*[a-zA-Z0-9])[^\-]-+$/' , '$2', $str); // This should be 'f-oo-oo' now - but it produced 'f-oo-o' echo $str; preg_replace() has to match your pattern as a whole in order to make a replacement. Your pattern says: Start at the beginning of the string, match one or more hyphens or "whitespace" characters (but only capture the first matched char), followed by a hyphen, followed by (and capture) 0 or more of any character followed by one number or letter (case-insensitive) (stop 2nd captured group). Then match one of anything that is not a hyphen, followed by one or more hyphens after that, followed by end of string. If you run that against a preg_match, you will see the following matches: Array ( [0] => Array ( [0] => --- ----- ------f-oo-oo---- ) [1] => Array ( [0] => - ) [2] => Array ( [0] => f-oo-o ) ) Your first piece ^(-|\s)+ matches this part: --- ----- ------f-oo-oo---- but your captured group (-|\s) only matches the last green - Then you have a literal "-" after that, which matches the final "-" before "f" (red part): --- ----- ------f-oo-oo---- Next, you have (.*[a-zA-Z0-9]) The .* will greedily match everything until the very end of the string, but then give up characters until it can match the rest of your pattern. Well the next thing in your pattern is your [a-zA-Z0-9] character class which matches a letter or number, so .* will match the blue part, and the character class will match that last "o" (orange part): --- ----- ------f-oo-oo---- But wait..then you have a negative character class that says match anything that is not a hyphen, so the .* has to back up one more time and give up the 2nd to last "o" as well, and then the [a-zA-Z0-9] can match that, and the [^\-] can match the last "o" (black): --- ----- ------f-oo-oo---- So the 2nd capture ($2 - the part with the 2nd parenthesis wrapped) in total is f-oo-oo Finally you have -+$ which matches one or more hyphens and then end of string, which matches the ending green: --- ----- ------f-oo-oo---- Soo...if you want to do it the regex way, a pattern more like this will work: $str = ' --- ----- ------f-oo-oo----'; $str = preg_replace('/^(-|\s)+|(-|\s)+$/' , '', $str); // This should be 'f-oo-oo' now - but it produced 'f-oo-o' echo $str; This pattern says: Start at beginning of string and match one or more hyphens or whitespace characters, OR match one or more hyphens or whitespace characters followed by end of string, and replace with "" (nothing).
-
Does phpFreaks have any sister sites?
.josh replied to kansasakki's topic in PHPFreaks.com Website Feedback
If nobody is answering your question, I would also advise that you step back and take a look at the question you asked. 9/10 times I see a question going unanswered not because people don't know the answer, but because the poster doesn't know how to properly ask a question. They tend to assume many things, short of the audience being psychic (and they expect even that sometimes!). Pretend you are someone else reading it and have no prior knowledge of the context for which you are working in. Did you provide enough back-story and detail? Did you provide enough relevant code? Did you clearly and accurately explain the situation, what you are doing, what is not working, what you expect? Etc.. This is especially important with Javascript, because there are literally a billion different things that could be causing something to go wrong. With php, there's only so many things that could be the culprit. The script is being run on one server and doesn't care about multiple browsers etc.. It is a single script running and the only other scripts that might be an issue are what you specifically include in php. But with Javascript...you have to worry about different browsers and browser versions. Even javascript syntax itself varies from browser to browser! You have to worry about random addons/extensions/plugins adversely affecting something. You have to worry about whatever other script includes are on the page, like frameworks, etc.. -
Do People on Here Have Websites Which Generate Some $$$ ?
.josh replied to chaseman's topic in Miscellaneous
Kinda sidetracking and nitpicking here...but if you are offering something that others don't offer, doesn't it go without saying that you are doing a better job than them at it? I mean, if you are the only one offering something, you are by default the one offering the best of it. One thing does not go hand in hand with the other, only because you're offering something which the others don't does not mean you're better off, people may not need, want, or even hate the unique feature you're offering. That special something you're offering must be a killer feature which will make people switch sides. Right. You can offer something that is complete crap, but that's not really the point. Whether you make $1 or $1,000,000 off it, you're still doing better than everybody else making $0 off it, because they are not doing it at all. This is true as well, however, this doesn't fall under the "Offer something that the others don't" category.