-
Posts
14,780 -
Joined
-
Last visited
-
Days Won
43
Everything posted by .josh
-
As kicken said, as a guide, right-click and view the source on the demo page. You can see all of the html, css and javascript. You can see that they point to google's hosted jquery library. Then they put the slider code in a separate js file, which is a good practice. Then there's one line of javascript code after the 2 script includes, which is probably the trigger to load up and start running the slider. Just look at the source of the demo page.
-
jQuery is a javascript library. You "install" it by adding a javascript script tag on your page(s). You can grab the latest version off jquery.com and host it yourself, or as an alternative, you can point to the one hosted by google, MaxCDN, etc..
-
okay if you are trying to find out if the variable a exists, then why are you even trying to pass it to your function? But to check for it, you would use quotes: if ("a" in window)
-
Okay, so if you look in your js console, you can see that you get an error when you click on the link: Uncaught ReferenceError: a is not defined This is happening because in your onclick, you are attempting to pass a variable that doesn't currently exist: <a href="#" onclick="newFunc(a);">click</a> IOW newFunc(a) throws an error when it's called because a doesn't exist. And then lets look at your actual function.. I'm still a bit unclear on what you're trying to actually accomplish, but this is wrong: if(window[a] in window) { Look back at the link I gave you about in. It's supposed to be prop in objectName but you are doing objectName[prop] in objectName And whether or not it should be wrapped in quotes depends on what you are actually trying to look for. Are you trying to check if a exists as a variable, or are you trying to check if the value of a exists as a variable? IOW: let's say I have var a = "foobar"; Are you trying to find out if the variable a is defined, or are trying to find out if there is a variable foobar defined?
-
Okay well then you are leaving out some kind of detail then, because yes you most certainly can check if global variables are undefined from within a function, exactly how I showed you in my first post, or else using the in operator as you did. Perhaps you should elaborate on "it doesn't work". Can you show your actual code, and how you are calling it? Post your code on jsfiddle.net so that I may see your "not working" code in action.
-
IOW if you want to pass a value to your function and check if that variable exists, do this: function someFn(myVar){ if (typeof window[myVar]=='undefined') { alert('variable is not defined'); } else { alert('variable is defined'); } } someFn('foobar'); // variable is not defined var foobar = 'blah'; // now lets define it someFn('foobar'); // variable is defined
-
okay first off, you have "myVar" in quotes in your condition, which means it's looking for that literal variable, not the value you pass to your function. So unless window.myVar (or window['myVar']) exists, it's going to be false, no matter what you pass to your function. So basically, it looks like you want to pass a value myVar to your function and then check if it exists in the global scope (e.g. - you pass "foobar" and you want to check if the variable foobar exists). If that is the case, remove the quotes around myVar. But 2nd, why are you using the "in" operator in the first place? This isn't the best way to go about it, and can produce some unexpected behavior. Read up here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/in
-
It depends on the variable's scope. If the variable really is in the global scope, you should be able to do this: if (typeof window.yourVariable=='undefined') { ... } or if (typeof window['yourVariable']=='undefined') { ... } If neither of those are working, then the variable isn't really globally scoped. Maybe the variable is really a property of some other variable that's globally scoped, e.g. window.someParentVariable.yourVariable or else the variable was defined within some other function or something.
-
if ($age < 20 && age > 10) { // $age is between 10 and 20 }
-
You need to name your form elements and then look at $_POST or $_GET depending on what method you used for your form. Here is a simple example: <?php echo "<pre>";print_r($_POST);echo "</pre>"; ?> <form action='' method='post'> <input type='text' name='myTextField' /> <br/> <textarea name='myTextArea'></textarea><br/> <input type='submit' name='submit' value='submit' /> </form> now when you fill out the form, you will see something like this: Array ( [myTextField] => text field value [myTextArea] => textarea value [submit] => submit ) So for example, $_POST['myTextField'] will have whatever you entered in the text field.
-
are you serious? This is a joke, right? Seriously, who's trolling..
-
Displaying information from database onto website
.josh replied to WilliamNova's topic in PHP Coding Help
There are a million reasons why your code could have failed. We cannot even begin to help unless you post the code you tried and errors it output. Then you ask for us to not just *give* you code, but break it down and explain it.. well that's what tutorials are for. There are literally thousands of basic database interaction tutorials out there (including on this site). What tutorials have you looked at? What part of them don't you understand? To be clear, you're going to need to be a lot more specific than making general statements about how you failed and want help. -
also fyi == is a loose comparison, so anything that would evaluate to 0 (e.g boolean false) will make that condition true. If you want to be more accurate about evaluating the return codes, use === instead.
-
$Spingstatuscode != $pingstatuscode
-
A form can have any number and type of elements(text fields, radio buttons, checkboxes, hidden fields, dropdowns, etc.). $_POST is an array of all the form elements and their values that was submitted. Depending on how complex the form is, $_POST can be anything from an array with a single element, to a multi-dimensional array. For example, with a simple form like this: <?php echo "<pre>";print_r($_POST);echo "</pre>"; ?> <form action='' method='post'> <input type='text' name='email' /> <input type='submit' name='submit' value='submit' /> </form> $_POST will look like this: Array ( [email] => [email protected] [submit] => submit ) But with a more complex form, like one with checkboxes: <?php echo "<pre>";print_r($_POST);echo "</pre>"; ?> <form action='' method='post'> <input type='text' name='email' /> <br/> <input type="checkbox" name="animals[]" value="dog" />dog <br/> <input type="checkbox" name="animals[]" value="cat" />cat <br/> <input type="checkbox" name="animals[]" value="mouse" />mouse <br/> <input type='submit' name='submit' value='submit' /> </form> $_POST will look like this: Array ( [email] => [email protected] [animals] => Array ( [0] => dog [1] => mouse ) [submit] => submit ) So from this, is_array($_POST['email']) would be false, since that is just a string "[email protected]". But is_array($_POST['animals']) would be true. Checking whether or not the posted value is an array may or may not be relevant to the actual code example in the book; you'd have to post the form code from the book for us to determine that.
-
Near as I can tell, you're using preg_split in a funky way. Normally it's used for splitting with patterned delimiters, not for directly capturing stuff. IOW, near as I can tell, you were making the thing you wanted to match the delimiter and then using PREG_SPLIT_DELIM_CAPTURE to flip the roles of delimiter/split content, in order to effectively match for what you wanted. You can do it this way, but it's a funky ass-backwards way of doing it. Instead, when you should just be use the straightforward preg_match_all function instead. This is how you would normally do it: You use preg_match_all to match for your stuff: $option = array(); $regex = '~\[([^\]]+)\]~'; $input = "[input 1] [input 2] [input 3]"; preg_match_all($regex, $input, $matches); $option = $matches[1]; If you really want to go the preg_split route, normally you would split by the delimiter, which is "] [". I threw some alternation into the mix, along with the PREG_SPLIT_NO_EMPTY flag, as a means to effectively strip the leading "[" and trailing "]" but alternatively (and perhaps ideally) you could instead trim $input first, to get rid of them, so that the preg_split pattern would only be dealing with the delimiter. $option = array(); $regex = '~^\[|\]\s+\[|\]$~'; $input = "[input 1] [input 2] [input 3]"; $option = preg_split($regex, $input, -1, PREG_SPLIT_NO_EMPTY);
- 3 replies
-
- array
- preg_split
-
(and 1 more)
Tagged with:
-
If a string contains "NOT word" how to replace it with "-word"?
.josh replied to the5thace's topic in PHP Coding Help
the search/replace logic is failing because you are urlencoding the string before doing the search/replace, which is changing " " to "+". Perhaps you meant to urldecode instead? Or perhaps that urlencode needs to happen after this search/replace. In any case, $Bquery = preg_replace('~(?<=\b)(not\s+(?=\w))~i','-',$Bquery); This will replace "not " with "-" only if there's a word character after it. Examples: "cat not dog" > "cat -dog" "not dog" > "-dog" "cat not" > "cat not" "cat not " > "cat not " "cat not ?&$S" > cat not ?&$S" "cat not 12345" > cat -12345" -
while ( $mem_row = mysql_fetch_array( $result ) ) { // .. }
-
It gives me incentive to delete things.
-
Hello All, We have a http://forums.phpfreaks.com/topic/273124-readme-everything-youd-want-to-know-about-php-freaks/#entry1405504'>sticky that explains what the badges under members' names are, but a Guru in particular is basically anybody who has demonstrated that they are actively trying to be a part of the phpfreaks community and in general know wtf they are talking about. You don't have to be some super ninja expert at everything, nor do you have to be posting 100 posts a day to achieve this rank. Traditionally the process for "gaining rank" around here involves you joining our community and making an effort to help others out with their questions. And after a while of this, one or more members of the staff (guru, mod or admin) may take notice of your efforts and then nominate you to join the ranks (this happens internally). In addition, we try to look at things like rep and posts marked solved to find you. But maybe you feel like you've been making an effort for naught. Most of us don't regular all the forums; we just hang around the ones we are the strongest at or most interested in. So maybe the one thing you're really good at is the one forum nobody else really hangs out in. Or maybe the stars just don't seem to align right or something. So, in order to ensure that nobody feels like they are going unnoticed, I want to extend the nomination process to the entire community. If you feel like you've been hanging around and helping out for a while and have what it takes to wear a Guru badge, or if you know someone around here who does, please post your nominations here, as a way to ensure yourself or someone else is on our radar. .josh
-
The biggest setback is the fact that you don't want to include #asdfasd. That one isn't actually inside an html tag the same way as #bbbbbb. By this logic..what would you say to the following? <p>#testing <span style="color: #bbbbbb">#asdfasd</span> #test</p> or <div>#testing <span style="color: #bbbbbb">#asdfasd</span> #test</div> or <body>#testing <span style="color: #bbbbbb">#asdfasd</span> #test</body> Point is virtually everything is "in" an html tag somehow. I can make a difference between #bbbbbb and the other 3, because #bbbbbb is part of a value in an html element attribute. But strictly speaking, there is no difference between #asdfasd and the #test or #testing. So first off, you need to be more specific about what you actually want to ignore. Anything inside an html tag or span tag specifically? In any case, regex isn't really the best tool for parsing html. You should instead use a DOM parser to traverse the html elements.
-
honestly I don't know what your hosting provider will or won't do for you..I've never done this stuff on a shared hosting account before, only a dedicated box :/
-
It's an actual password
-
Yeah i thought that would be the case...basically you're out of luck, since your script can't point to the certificate files. That's how it usually is on shared hosting. If you really really need to make this script work, you need to move to a dedicated box where you get full access and can point your script to the certificate files.
-
Cannot use string offset as an array when trying to echo an array
.josh replied to the5thace's topic in PHP Coding Help
Your array is only two levels deep..you are trying to echo it as if it is 5 levels deep. If you just want to dump the contents of the array for QA, do this: $bing_results[$b] = array ('url' => $value->Url, 'title' => $value->Title, 'snippet' => $value->Description, 'rank' => 100-$b); echo 'Lets see? : <br/>'; echo '<pre>'; print_r($bing_results[$b]); echo '</pre>'; $b++; If you want to echo individual elements, do for example this: $bing_results[$b]['url'] or $bing_results[$b]['title']