Jump to content

Alex

Staff Alumni
  • Posts

    2,467
  • Joined

  • Last visited

Everything posted by Alex

  1. This works for me: $pages =<<<TEXT <li class="page_item page-item-27"><a href="http://www.domain.tv/news/" title="News">News</a></li> <li class="page_item page-item-30"><a href="http://www.domain.tv/resources/" title="Resources">Resources</a></li> <li class="page_item page-item-31"><a href="http://www.domain.tv/submit/" title="Submit">Submit</a></li> TEXT; $pages = preg_replace('~\s*class="page_item page-item-[0-9]+"\s*~', '', $pages); echo $pages; Output: <li><a href="http://www.domain.tv/news/" title="News">News</a></li> <li><a href="http://www.domain.tv/resources/" title="Resources">Resources</a></li> <li><a href="http://www.domain.tv/submit/" title="Submit">Submit</a></li>
  2. Post your exact code and what you're exactly trying to match, I tested the code I posted with what you provided and it worked fine.
  3. And to do something like that this should work: $new = array(); foreach($withoutBreaks as $val) { $parts = explode(' ', $val); $new[substr(array_shift($parts), 1)] = implode(' ', $parts); } I made the assumption that the first word is the name and the rest is the value. Wasn't completely sure if it should be like 'Site Room' => 1 or 'Site' => 'Room 1', this code should do the latter.
  4. I was thinking you could do something like this, to avoid having to do multiple preg_*() calls (but I wasn't sure which would be faster, so I did a benchmarking test): preg_match_all("/(?<=\A|[^A-Za-z0-9_])@([A-Za-z0-9_]+)(?=\Z|[^A-Za-z0-9_])/", $text, $matches); for($i = 0, $n = sizeof($matches[0]);$i < $n;++$i) { $text = str_replace($matches[0][$i], "<a href='/user/{$matches[1][$i]}' target='_blank'>{$matches[0][$i]}</a>", $text); } // Use $matches[1] for the usernames to notify Ran 1000 times took an average of about 0.15 Seconds This turned out to actually be faster: $text = preg_replace("/(?<=\A|[^A-Za-z0-9_])@([A-Za-z0-9_]+)(?=\Z|[^A-Za-z0-9_])/", "<a href='/user/$1' target='_blank'>$0</a>", $text); preg_match_all("/(?<=\A|[^A-Za-z0-9_])@([A-Za-z0-9_]+)(?=\Z|[^A-Za-z0-9_])/", $text, $matches); // Use $matches[1] for the usernames to notify Ran 1000 times took an average of about 0.10 Seconds Just because I was curious I ran my original solution through too, and that took an average of about 0.085 seconds / 1000 loops.
  5. You misunderstood the question. mapleleaf was simply asking how to search a string of words for a certain word and did not want, for example, "Color" to match because "Colorado" was in the string.
  6. Something like this? $string = preg_replace('~\s*class="page_item page-item-[0-9]+"\s*~', '', $string);
  7. In your array it's [EventDate 2010.06.18 not [Date 2010.06.18 Edit: Since you modified your post it leads me to believe you want something more like this: foreach($withoutBreaks as $key => $val) { if(substr($val, 0, 11) == '[EventDate ') { echo "Key: $key<br />\n"; break; } }
  8. You can use preg_match along with the \b modifier. if(preg_match("~\b{$_GET['word']}\b~", $file)) { // Found } else { // Not found }
  9. You can't get the MAC address of a visitor in PHP. You'll have to look into another method of user verification.
  10. Use preg_replace_callback, and in the callback you can do whatever you need to do to each match. It might look something like this: $text = preg_replace_callback( "/(?<=\A|[^A-Za-z0-9_])@([A-Za-z0-9_]+)(?=\Z|[^A-Za-z0-9_])/", create_function( '$matches', /* do whatever you need to do */ 'return "<a href=\'/user/{$matches[1]}\' target=\'_blank\'>{$matches[0]}</a>";' ), $text );
  11. <?php function image_captcha_verification($width = NULL, $height = NULL, $words = NULL) { $font_size = "18"; $border_colour = "239, 239, 239"; $font = "verdana.ttf"; $width = "400"; $height = "80"; $words = array ("police", "time", "broadway", "is", "throughout", "hateful", "action", "duvet", "tailcoat", "the", "danger", "minster", "army", "dent", "share", "beard", "lazy", "year", "must", "resigned", "angry", "relapse", "trump", "union", "adventure", "honey", "inject", "special", "end", "crossing", "slow", "grunge", "prize", "of", "dreamer", "issues", "tomcat", "riverbed", "founder", "working", "mask", "spinned", "reported", "meets", "john", "by", "vogue", "said", "jumpy", "democratic", "kingdom", "combs", "moments", "peaks", "rise", "innocent", "chalked", "from", "relations", "removing", "platform", "unwillingness", "secretary", "computer", "arranger", "mentor", "was", "quote", "warn", "rally", "squadron", "profiles", "immature", "in", "drives", "train", "intrude", "state", "defense", "past", "plunges", "cry", "cameras", "promises", "outskirt", "subtitles", "hidden", "logic", "advertisement", "exact", "dimond", "risk", "director", "back", "sinatra", "store", "stopgap", "equal", "housing", "airport", "him", "security", "one", "dodges", "development", "entertainer", "ignition", "lovebird", "counts", "world", "protocol", "than", "cry", "shannon", "shear", "drain", "blues", "morning", "fronting", "executive", "person", "reached", "taxplayer", "stranger", "schedules", "preston", "historic", "featured", "port", "tricked", "announced", "can", "time", "loadable", "wallets", "wounded", "core", "empire", "towers", "wished", "confused", "who", "hurdles", "toggles", "martin", "defender", "plane", "decked", "but", "harp", "ribs", "helpers", "least", "column", "cement", "room", "tension", "clipper", "shudder", "dangles", "storm", "farms", "zero", "affairs", "maniacs", "proposals", "two", "surrounded", "bone", "difficult", "dusters", "sailed", "bonding", "speak", "however", "sands", "scribble", "maiden", "mouths", "arms", "coopered", "learned", "recieved", "rocks", "tripod", "skull", "dwarf", "number", "arrested", "squish", "singer", "buttered", "found", "new", "million", "token", "combo", "completed", "national", "markets", "because", "lower", "trainers", "chief", "angle", "seabed", "trickled", "firsy", "undated", "ludlow", "stones", "joker", "monster", "reach", "outlook", "aware", "among", "comfort", "living", "contact", "french", "thailand", "open", "yelps", "delayed", "smart", "metropolitan", "meter", "snow", "castle", "tools", "irrigration", "new", "gas", "sidestepping", "drys", "cartoons", "declared", "numskull", "brass", "sped", "washington", "landing", "ordeal", "cops", "quiet", "strike", "destruct", "wrote", "mamma", "tunes", "balanced", "officers", "books", "flame", "am", "fishing", "not", "inspires", "beehives", "hypnotic", "flops", "sandhurst", "invoked", "bullion", "christmas", "muttered", "moats", "baggy", "ginger", "obligated", "hangover", "building", "midland", "mocks", "heavy", "don", "quotable", "clarkson", "vary", "enriches", "romania", "sumo", "ushering", "votes", "cool", "resumed", "sprayers", "convents", "unchanging", "prove", "renshaw", "holy", "recited", "kingpins", "valiant", "yesterday", "withdrawel", "itself", "slog", "marry", "newborns"); $image = imagecreatetruecolor($width, $height); $background = imagecolorallocate($image, 255, 0, 0); $text = imagecolorallocate($image, 20, 40, 100); imagefill($image, 0, 0, $background); //imagefilledrectangle($image, 0, 0, $width - 1, $height - 1, $border_colour); imagecolortransparent($image, $background); $random_key = array_rand($words, 2); $string = $words[$random_key[0]] . " " . $words[$random_key[1]]; $array = preg_split("//", $string, -1); $array_length = count($array) - 1; for($i = 1; $i < $array_length; $i++) { $letter = $array[$i]; if ($letter == " ") { // ucfirst //lcfirst //strtolower //strtoupper //ucwords } $letter_spacer = 25 * $i; $angle = rand(1, 25); $x_coordinates = 50 + $letter_spacer; $y_coordinates = ($height / 2); imagettftext($image, $font_size, $angle, $x_coordinates, $y_coordinates, $text_colour, $font, $letter); } session_start(); $_SESSION['captcha_code'] = md5($string); header("Content-type: image/png"); imagepng($image); imagedestroy($image); } image_captcha_verification(); ?>
  12. Yea, this is a much better idea. Using $_SERVER['PHP_SELF'] leaves you open to XSS attacks. Or if you want it to be 'valid' you can just put the name of the file.
  13. Oh yeah, I meant to mention that in my post as well. I think 3 would be the best.
  14. No. You will have to use OR like so: SELECT * FROM table WHERE col LIKE '%something%' OR col LIKE '%somethingelse%' If you have an array containing terms you want to use with LIKE you can do something like this: $terms = array( 'term1', 'term2', 'term3' ); $sql = "SELECT * FROM table WHERE col LIKE '%" . implode("%' OR col LIKE '%", $terms) . "%'";
  15. You can use imagecolortransparent to set a color to transparent on the image.
  16. Use urlencode to encode the & for the url.
  17. Well that's what I get for blindly looking at the code I guess. You don't need the single quotes there regardless. $sql = "SELECT * FROM $table";
  18. $_REQUEST = array_map('urldecode', $_REQUEST);
  19. Your first error is because single quotes don't have variable interpolation. Meaning that in this statement: $sql = 'SELECT * FROM "$table"'; $table is being taken as a literal string, not a variable. So you need to do this: $sql = "SELECT * FROM '$table'"; You're also forgetting a $ here: function listQuery(categories, $connection) { It should be: function listQuery($categories, $connection) {
  20. You need to pass the connection, $connection in your case, to mysqli_error().
  21. Are you sure you have the GD library installed? Use phpinfo to see if you do.
  22. You should really look into variable scopes. Your problem is that $connection is not defined within your function, listQuery(). One solution is to pass $connection as a parameter like so: require_once("/functions/db_fns.php"); $connection = dbConnect(); echo listQuery("categories", $connection); function listQuery($table, $connection) { // prepare the SQL query $sql = 'SELECT * FROM $table'; $result = $connection->query($sql) or die(mysqli_error()); // find out how many records were retrieved $numRows = $result->num_rows; while ($row = $result->fetch_assoc()) { echo strtoupper("<li>{$row["cat_name"]}</li>"); } }//end function
  23. Look into mod_rewrite. If you have further questions about mod_rewrite there's a board you can ask questions on here.
  24. The first parameter has to either be a string of name of the class you're testing or either an instance of the class. So in your example either 'test' or $test. The second parameter has to be a string, 'test2'. if (method_exists($test, 'test2')){ echo "found method"; } or if (method_exists('test', 'test2')){ echo "found method"; }
×
×
  • 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.