-
Posts
14,780 -
Joined
-
Last visited
-
Days Won
43
Everything posted by .josh
-
If you don't want to change the script, how do you expect to make it do something more than what it already does?
-
view the source on your own page. rightclick on your script include and copy the url. paste it into your browser. Does the code show up, or do you get a 404 (file not found) error?
-
okay, the page you linked..had a bunch of javascript on it..that javascript is the plugin, the code for the slider. If you view the source of the demo, and then view the source of that js/jquery.catslider.js script include, you can see that it's the same code they showed you to add to the page. They just put it into a file and included the file on the page, for convenience. You need to save that javascript to a file and upload it to your server, and you need to change that script include to point to wherever you uploaded the file to. The demo has the file in a js subfolder, so you can create a subfolder on your server and put it there, or you can put the js file in the same directory as your page and then remove that part of the path in the script include. Do you understand how pathing works? Pathing isn't even javascript specific. Alternatively, you can just c/p the catslider.js code directly on your page (somewhere underneath the jquery script include - making sure it's wrapped in script tags). But most people put code in a separate js file because it's easier to organize and update stuff. Also, if you just blindly copy/pasted their source, then you probably will need to give a shit about the images, seeing as how this script has to do with images and probably won't work, or work funky or something, if the images don't exist..
-
come on man, use your brain. Most of the URLs in the script includes, css links and img src's are relative. You need to change them to point to your own hosted stuff. Did you upload the scripts and images and stuff to your own server?
-
well.. you didn't really provide details about how you wanted the text to be returned.. but here is one way to do it: preg_match('~<tr>.*?ABC Football Club.*?</tr>~is',$content,$match); if (isset($match[0])) $text = strip_tags($match[0]); $content is the text you are trying to extract the info from, and $text will then contain something like this: 17-Aug-2013 Sat 5 PM XYZ Club FC vs ABC Football Club APSM Pitch Basically the code grabs the first tr block that has that "ABC Football Club" string within it, and then strips all the html tags from it, leaving the text and linebreaks. From there, it kinda depends on what you're going for, but I assume you don't need help as far as string manipulation..
-
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] => foo@bar.com [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] => foo@bar.com [animals] => Array ( [0] => dog [1] => mouse ) [submit] => submit ) So from this, is_array($_POST['email']) would be false, since that is just a string "foo@bar.com". 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