
-Karl-
Members-
Posts
421 -
Joined
-
Last visited
Everything posted by -Karl-
-
Nevermind, fixed it myself: function buildPosts($array) { $new_array = array('left' => array(), 'right' => array()); $i = 0; foreach($array as $val) { if($i == 0) { $new_array['left'][] = $val; $i = 1; } else { $new_array['right'][] = $val; $i = 0; } } return $new_array; } Thanks for the advice though guys!
-
Hmm, but how would I return it from the function?
-
Hello, I need a more efficient way of alternating an array in order to display them left and right. At the moment I have my HTML: <div class="left"> //This floats everything within the div to the left //Echo buildLeft </div> <div class="right"> //This floats everything within the div to the right //Echo buildRight </div> Then I have the following PHP code in order to take the current array, which is all the results and manipulate it: function buildLeft($array) { $new_array = array(); $i = 0; $count = count($array); while($i < $count) { $new_array[] = $array[$i]; $i = $i+2; } return $new_array; } function buildRight($array) { $new_array = array(); $i = 1; $count = count($array); while($i < $count) { $new_array[] = $array[$i]; $i = $i+2; } return $new_array; } The code works fine and does what I need it to do, but I just don't think it's very efficient, especially when the beginning array could be quite large, then I'm running it through both of these functions. Any ideas?
-
Aye, that's a lot of useful functions that hide away in the PHP docs!
-
Okay, just use in_array() instead: if(in_array($username,$words)) { $errors = "<font color='red'>* Username contains prohibited words</font><br>"; } If that returns an error it must be something to do with what you're passing through to the variables.
-
if(strpos($username, $words)) { $errors = "<font color='red'>* Username contains prohibited words</font><br>"; } Etc, you don't need quotes, otherwise it looks for the string, not the variable.
-
Ended up doing an explode: $parse = parse_url($image); $url = $parse['host']; $explode = explode('.',$url); if(count($explode) > 2) { $url = $explode[1].'.'.$explode[2]; } Just need to do some testing for all possible variables now.
-
If you read my first post, parse_url() is exactly what I am using... I then explained the reason why it's not suffice.
-
Not really, since 456.imageshack.us/image.png contains three periods, whereas tinypic.com/image.png contains two.
-
Hello, I'm having difficulty extracting the root domain from an URL, whilst excluding a subdomain if one is there. Basically: $txt = 'http://i.imgur.com'; $parse = parse_url($txt); $url = $parse['host']; Returns i.imgur.com, but I only need imgur.com. However, the reason it's complicated is because the url could also be www.imgur.com, so you can't simply explode by ".", then there's also the problem with other tld's. For example, m465.imageshack.us, all I need it to return is imageshack.us. What would be the best way to achieve this?
-
We're talking on msn, thus I'm not keeping this thread updated and you're being an idiot, I've obviously changed the things you've just stated yet you still reply here with your nonsense.
-
Indeed, but I already tried that so was just messing around. $txt = '[img=tinypic.com][img=imageshack.us]'; if(preg_match_all("#\[img\](.+?)\[/img\]#i",$txt,$match)) { $whitelist = array('tinypic.com','imageshack.us','photobucket.com','pure-warfare.com','i.imgur.com','imgur.com','deviantart.com','runescape.com','jagex.com','puu.sh','google.com','facebook.com'); $good_url = 0; $i = 0; foreach($match[0] as $image) { foreach( $whitelist as $url ) { $url = preg_quote( $url, '/' ); $url = str_replace( '\*', "(.*?)", $url ); if( preg_match( '/' . $url . '/i', $image[$i] ) ) { $good_url = 1; } } $i++; } if(!$good_url) { echo 'error'; //$this->error = 'invalid_image_host'; } else { echo $txt; } } Still doesn't work, just echos error.
-
This still returns an error, I just can't figure out why... $txt = '[img=tinypic.com][img=imageshack.us]'; if(preg_match_all("#\[img\](.+?)\[/img\]#i",$txt,$match)) { $whitelist = array('tinypic.com','imageshack.us','photobucket.com','i.imgur.com','imgur.com','deviantart.com','puu.sh','google.com','facebook.com'); $good_url = 0; $i = 0; foreach($match as $image) { foreach( $whitelist as $url ) { $url = preg_quote( $url, '/' ); $url = str_replace( '\*', "(.*?)", $url ); if( !preg_match( '/' . $url . '/i', $image[$i] ) ) { $good_url = 1; if($good_url = 1) { $bad = $image[$i].$i; } } } $i++; } if($good_url == 1) { echo $bad; //$this->error = 'invalid_image_host'; } }
-
Hello, I'm trying to find a way to filter out image hosts which aren't currently on a "whitelist", so far I have the following which works fine, but only for one preg_match. So obviously I need to change it to preg_match_all, then to another foreach. Basically, foreach image found, loop through the whitelist. However, I've been experimenting and I just can't get my head around it. This is what I have so far for just checking one instance. $txt = '[img=http://i.imgur.com/thisworks.png][img=http://i.imdddgur.com/doesntwork.png]'; if(preg_match("#\[img\](.+?)\[/img\]#i",$txt)) { $whitelist = array('tinypic.com','imageshack.us','photobucket.com','imgur.com','deviantart.com','puu.sh','google.com','facebook.com'); $good_url = 0; foreach( $whitelist as $url ) { if($good_url == 0) { $url = preg_quote( $url, '/' ); $url = str_replace( '\*', "(.*?)", $url ); if( preg_match( '/' . $url . '/i', $txt ) ) { $good_url = 1; } } } if(!$good_url) { $this->error = 'invalid_image_host'; } } And this is what I had for the preg_match_all which I can't get to work: $txt = '[img=http://i.imgur.com/thisworks.png][img=http://i.imdddgur.com/doesntwork.png]'; if(preg_match_all("#\[img\](.+?)\[/img\]#i",$txt,$match)) { $whitelist = array('tinypic.com','imageshack.us','photobucket.com','imgur.com','deviantart.com','puu.sh','google.com','facebook.com'); $good_url = 0; $i = 0; foreach($match as $image) { foreach( $whitelist as $url ) { if($good_url == 0) { $url = preg_quote( $url, '/' ); $url = str_replace( '\*', "(.*?)", $url ); if( preg_match( '/' . $url . '/i', $image[$i] ) ) { $good_url = 1; $hi = $image[$i]; } } $i++; } } if(!$good_url == 1) { $this->error = 'invalid_image_host'; } } Any ideas?
-
Indeed, but if I add countsign = 0; to the mouseup section, for if somewhere else in the document is click. Then it breaks the functionality of the clicking of the link twice.. So I have no idea what I can do.
-
Does now that I've changed the code completely. But still if you click off the div, somewhere else on the document, it takes 2 clicks to show the menu again..
-
So when you clicked "login" it showed, then when you clicked it again, it hid it? Because it doesn't work for me on Chrome or Firefox.
-
Hello, I've tried implementing: http://aext.net/2009/08/perfect-sign-in-dropdown-box-likes-twitter-with-jquery/ Which works perfectly, it shows when you click the link, then if you click it again it hides it. It also hides if you click anywhere else on the document whilst it's open. I've tried implementing in to this page: http://hevvo.eu/~dev/backtrack/index.php However, it only works when you click on it, then click on the document, not if you click on the link again. I just can't figure out what's different about my code.. Any help would be greatly appreciated.
-
Sorry but I'd prefer not to have a cancel button, it would make the drop down forms look untidy imo.
-
Yeah but that doesn't work for when a user clicks off the div on the rest of the document. It also doesn't change the CSS style, the border is different for when the menu is open and when it's closed. Also, if loginForm is displayed and regsiterForm is clicked, I need loginForm to hide. So that's not really possible by simply using returns.
-
After more messing around I've come up with: $(document).ready(function() { $('#login').toggle(function() { $(".login-form").show(); $(".login").css("border-bottom","1px solid #add0d0"); }, function() { $(".login-form").hide(); $(".login").css("border-bottom","1px solid #d1e8e8"); }); $(".login-form").mouseup(function() { return false }); $(document).mouseup(function(e) { if($(e.target).parent("a.sign-in").length==0) { $(".login-form").hide(); $(".login").css("border-bottom","1px solid #d1e8e8"); } }); $('#register').toggle(function() { $(".register-form").show(); $(".login").css("border-bottom","1px solid #add0d0"); }, function() { $(".register-form").hide(); $(".login").css("border-bottom","1px solid #d1e8e8"); }); $(".register-form").mouseup(function() { return false }); $(document).mouseup(function(e) { if($(e.target).parent("a.reg").length==0) { $(".register-form").hide(); $(".login").css("border-bottom","1px solid #d1e8e8"); } }); }); The only problem is, if you click on the link, then click off on to the document to hide the div, then click back on the link you need to click it twice for it to show again. Is there a way to reset toggle in order to avoid having to click twice?
-
Almost correct, I don't want the form to close just if the mouse leaves, only when a person clicks off the form, anywhere else on the page.
-
Ahh right, I'm quite new to jQuery, do you have any suggestions how I could go about doing this?
-
Just had a mess around, what is wrong with this? Because it shows, but then it won't hide when it's clicked again. login is definitely set to true as I tested with alerts. $(document).ready(function() { var login = false; if ( login == false ) { $("#login").click(function(e) { $('.login-form').show(); login = true; }); } if ( login == true ) { $("#login").click(function(e) { $('.login-form').hide(); alert(login); login = false; alert(login); }); } });