Jump to content

-Karl-

Members
  • Posts

    421
  • Joined

  • Last visited

Profile Information

  • Gender
    Male

-Karl-'s Achievements

Regular Member

Regular Member (3/5)

0

Reputation

  1. 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!
  2. Hmm, but how would I return it from the function?
  3. 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?
  4. Aye, that's a lot of useful functions that hide away in the PHP docs!
  5. 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.
  6. 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.
  7. 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.
  8. If you read my first post, parse_url() is exactly what I am using... I then explained the reason why it's not suffice.
  9. Not really, since 456.imageshack.us/image.png contains three periods, whereas tinypic.com/image.png contains two.
  10. 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?
  11. 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.
  12. 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.
  13. 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'; } }
  14. 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?
  15. Nvm fixed it.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.