PHP - Find X, Y For Specific Colour
I'm wondering how I can find the x, y coordinates on an image in PHP where a specific colour lies. If there was a #000000 coloured pixel located on 127, 205, how could I use PHP to find the 127, 205 by just telling it #000000?
Similar TutorialsThis topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=315388.0 I use the Wholesale Suite Premium Prices plugin with WooCommerce. I have 6 specific wholesale roles out of 15 that I wish to hide two specific shipping methods from being selected for the 6 exceptions. I'm just trying this on my staging server at this time using a code snippet example that I found and modified for my specific conditions. Would the following work for this purpose? /* Hide specific shipping methods for specific wholesale roles */ add_filter( 'woocommerce_package_rates', function( $shipping_rates ) { // User role and shipping method ID to hide for the user role $role_shipping_method_arr = array( 'ws_silvia_silver' => array( 'Silvia Premium Standard Shipping (Tracking Service)'), 'ws_silvia_silver_pst_exempt' => array( 'Silvia Premium Standard Shipping (Tracking Service)'), 'ws_silvia_silver_tax_exempt' => array( 'Silvia Premium Standard Shipping (Tracking Service)'), 'ws_silvia_silver' => array( 'Silvia Union Standard Shipping (Tracking Service)'), 'ws_silvia_silver_pst_exempt' => array( 'Silvia Union Standard Shipping (Tracking Service)'), 'ws_silvia_silver_tax_exempt' => array( 'Silvia Union Standard Shipping (Tracking Service)'), 'ws_silvia_gold' => array( 'Silvia Premium Standard Shipping (Tracking Service)'), 'ws_silvia_gold_pst_exempt' => array( 'Silvia Premium Standard Shipping (Tracking Service)'), 'ws_silvia_gold_tax_exempt' => array( 'Silvia Premium Standard Shipping (Tracking Service)'), 'ws_silvia_gold' => array( 'Silvia Union Standard Shipping (Tracking Service)'), 'ws_silvia_gold_pst_exempt' => array( 'Silvia Union Standard Shipping (Tracking Service)'), 'ws_silvia_gold_tax_exempt' => array( 'Silvia Union Standard Shipping (Tracking Service)'), ); // Getting the current user role $curr_user = wp_get_current_user(); $curr_user_data = get_userdata($current_user->ID); // Wholesale Suite Roles if (isset($current_user) && class_exists('WWP_Wholesale_Roles')) { $wwp_wholesale_roles = WWP_Wholesale_Roles::getInstance(); $wwp_wholesale_role = $wwp_wholesale_roles->getUserWholesaleRole(); // Loop through the user role and shipping method pair foreach( $role_shipping_method_arr as $role => $shipping_methods_to_hide ) { // Check if defined role exist in current user role or not if( in_array( $role, $current_user->roles) ) { // Loop through all the shipping rates foreach( $shipping_rates as $shipping_method_key => $shipping_method ) { $shipping_id = $shipping_method->get_id(); // Unset the shipping method if found if( in_array( $shipping_id, $shipping_methods_to_hide) ) { unset($shipping_rates[$shipping_method_key]); } } } } } return $shipping_rates; }); Any insights as to how to accomplish this would be greatly appreciated. Lyse Hi. I am looking for a way to have a button that toggles the background colour of my website. So for instance, I will have one button called 'switch to light', when its clicked it switches the colour of the background to a light colour, and another button replaces this that says 'switch to dark', and so on. I have turned to PHP because it appears to be the only way I would be able to have the change saved throughout the site, when pages are refreshed. However, I am a complete newbie, so have no idea what to do! Anyone that can help is a life saver! Thanks This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=344421.0 Hi, I have looked everywhere for a way to do this and would be grateful for a pointer in the right direction. I want to change the background color of the div with the id of "loggedin", depending on the status. The status currently echos text depending on the value. Code: [Select] <div class="grid_12" id="loggedin"> <div> <ul id="loggedin"> <li><?php global $current_user; get_currentuserinfo(); echo 'Status : ' . $current_user->status . "\n";?></li> <li> <?php if ($current_user->status=="RED") echo "Red info"; ?> <?php if ($current_user->status=="GREEN") echo "Green info"; ?> <?php if ($current_user->status=="BLUE") echo "Blue info"; ?> <?php if ($current_user->status=="YELLOW") echo "Yellow info"; ?> </li> </div> </div> Thanks I have got a code working to generate a menu from a mysql table, but I wan't to know if it is possible to have the background colour change to a third option when active. I have 1 background colour for 'off', one for mouseover, but can't figure out how to tell it what they current page is so that it will use a different css class value, as the page obviously reloads after the link is clicked. Is it possible (hope my explanation makes some sence!) My code: At the moment mainNav a: and mainNav a:hover work ok but what I want is a mainNav a:active to stay on after the page has loaded Code: [Select] <?php //function to nest the menu tree function nest_child(&$nodes, $current) { if (!isset($nodes) || count($nodes) < 1) { return; } foreach ($nodes as $id => $item) { if ($current['parentdocid'] == $id) { if (!isset($item['children'])) { $item['children'] = array(); } array_push($item['children'], $current); $nodes[$id] = $item; } else { nest_child($item['children'], $current); } } } //functions to display the tree and expand as appropriate function menu_display($nodes, $display_id) { if (!isset($display_id) || ($display_id == '')) { $display_id = 1; } $result = node_display( array( 'doc_id' => 1, 'children' => $nodes ), $display_id ); return $result[1]; } function node_display($node, $display_id) { global $ROOT; $found = false; $text = ''; if (isset($node[children])) { foreach ($node[children] as $id => $child) { $text .= "<li class='mainNav'><a href='$ROOT/index.php?doc_id=$child[doc_id]'>$child[doc_name]</a>"; $result = node_display($child, $display_id); if ($result[0]) { $found = true; $text .= "<ol>$result[1]</ol>"; } if ($child[doc_id] == $display_id) { $found = true; if (isset($child[children])) { $text .= "<ol>"; foreach ($child[children] as $id => $grandchild) { $text .= "<li class='mainNav'><a href='$ROOT/index.php?doc_id=$grandchild[doc_id]'>$grandchild[doc_name]</a>"; } $text .= "</ol>"; } } $text .= "</li>"; } } if ((!$found) && ($display_id != 1)) { $text = ''; } return array($found, $text); } ?> <ul class="menu"> <?php //retrieve all the menu elements $result = mysql_query('SELECT * FROM docs ORDER BY doc_order ASC'); $menu = array(); while ($row = mysql_fetch_assoc($result)) { $menu[$row['doc_id']] = $row; } //nest the elements foreach ($menu as $id => $item) { if ($item['parentdocid'] != 1) { nest_child($menu, $item); unset($menu[$id]); } } //display the tree print menu_display($menu, $doc_id); ?> </ul> Hi I have a table that populated by a recordset, and wondered whether is was possible to make a row background colour = red where a particular cell = some text? I have been searching around and not managed to find anything of use. Any help would be appreciated. This topic has been moved to Editor Help (Dreamweaver, Zend, etc). http://www.phpfreaks.com/forums/index.php?topic=355418.0 Hey, What function / how would I find if a string has something? Say I have a string like: $string = 'Hello their! This is my post :) btw, my name is Justin.'; Say I wanted to find out if my name "Justin" is inside that string.. so: whateverfunction('Justin', $string) So I think you should get my idea now though Thanks a lot! Hi I downloaded a PHP script, copied at localhost and when I run it, it will not display all results instruction says that Globals should be off in PHP.ini and scripts should work while Globals are off. but I can't find php.ini in XAMPP. I tried xampp/apache/bin but I didn't find php.ini what should I do? The issue I'm having is that this query won't find a max value record if it has less than 5 votes. It'll only show the results of an entry has 5 or greater votes. Why is that? $contest_id = 5; $category_id = 8; $find_entries = $db->prepare("SELECT entry_id, user_id, votes FROM contest_entries WHERE contest_id = :contest_id AND category_id = :category_id AND e_status = :e_status AND votes = (SELECT MAX(votes) FROM contest_entries) LIMIT 1"); $find_entries->bindParam(':contest_id', $contest_id); $find_entries->bindParam(':category_id', $category_id); $find_entries->bindValue(':e_status', 0); $find_entries->execute(); $result_entries = $find_entries->fetchAll(PDO::FETCH_ASSOC); if(count($result_entries) > 0) { foreach($result_entries as $row) { $entry_id = $row['entry_id']; $user_id = $row['user_id']; $votes = $row['votes']; } echo $entry_id; } else { echo 'nothing'; } Edited June 26, 2019 by imgrooot I can not find the problem with this script I wrote. I am trying to show a web page provided that the $_GET['reg'] is registered by the user. I am trying to check that the $_GET['reg'] is registered by the user before the page with specific details is shown. For some reason even if the email address equals the email address in the DB the output still shows: <?php echo "I am sorry but this '$_GET[reg]' does not seem to be registered by you!"; ?> Can anyone see where I am going wrong - there is more than one 'reg' for each email address in the DB. Thanks <?php $email = $_POST['email']; $sql = "SELECT reg FROM sales WHERE email='$email'"; $result = mysqli_query($cxn,$sql) or die ("Couldn't execute query"); $data = array(); //This way we can hold multiple results $i = 0; //The index of the array to add the result to while($row = mysqli_fetch_assoc($result)) { if ($row['reg'] == $_GET['reg'] ) { //Why use two if statements? $data[$i] = $row['reg']; $i++; //increase the array index for the next while loop } else { echo "I am sorry but this '$_GET[reg]' does not seem to be registered by you!"; exit(); } } // THIS IS WHERE THE PAGE CONTENT IS ...................... ?> Hello I am new thought I would ask help here as I was not getting much help on another forum. I have this code Code: [Select] <?php header("content-type: text/xml"); $rssfeed = '<?xml version="1.0" encoding="UTF-8"?>'; $rssfeed .= '<rss version="2.0">'; $rssfeed .= '<channel>'; $rssfeed .= '<title>My Price Savings Coupons.com Feed</title>'; $rssfeed .= '<link>http://www.mypricesavings.com</link>'; $rssfeed .= '<description>This is coupons.com feed</description>'; $rssfeed .= '<language>en-us</language>'; $rssfeed .= '<copyright>Copyright (C) 2011 mypricesavings.com</copyright>'; function compareFeeds($a, $b){ //this function will compare the "val" array element of each $itemRSS if ($a["val"] == $b["val"]) { return 0; } return ($a["val"] < $b["val"]) ? -1 : 1; } $doc = new DOMDocument(); $doc->load('http://rss.coupons.com/xmlserve.asp?go=14520kk5210'); $arrFeeds = array(); foreach ($doc->getElementsByTagName('item') as $node) { $itemRSS = array ( 'val' => $node->getElementsByTagName('value')->item(0)->nodeValue, 'image' => $node->getElementsByTagName('image')->item(0)->nodeValue, 'link' => $node->getElementsByTagName('link')->item(0)->nodeValue, 'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue, 'exp' => $node->getElementsByTagName('activedate')->item(0)->nodeValue ); array_push($arrFeeds, $itemRSS); } usort($arrFeeds, 'compareFeeds'); foreach($arrFeeds as $itemRSS){ $descrip = '<![CDATA[ <p><a href="'.$itemRSS["link"].'"><img src="'. $itemRSS["image"].'" align="left" border="0" height="80" width="80" alt="'.$itemRSS["desc"].'"/></a></p>]]>'; $descrip .= '' .$itemRSS["desc"]; $rssfeed .= '<item>'; $rssfeed .= '<title>' . $itemRSS["desc"] . '</title>'; $rssfeed .= '<link>' . $itemRSS["link"] . '</link>'; $rssfeed .= '<pubDate>' . $itemRSS["exp"] . '</pubDate>'; $rssfeed .= '<description>'. $descrip . '</description>'; $rssfeed .= '</item>'; } $rssfeed .= '</channel>'; $rssfeed .= '</rss>'; echo $rssfeed; ?> The purpose of this code is to take http://rss.coupons.com/xmlserve.asp?go=14520kk5210 and turn it into a true RSS Feed. I currently have the php above at mypricesavings.com/coupons/couponsfeed.php I receive the error in google chrome on mac, however, in safari it does work, If I were to use RSS Graffiti on facebook it also errors Thank you for any help, Also, If there is a better more efficient way to accomplish what I am trying to do, please share with me so I may learn better Derrick I have rows being generated in a foreach loop. I need to find the time in the row before it (or maybe after it if my logic is screwed up) to see if the times are equal. If they are equal, I need to see if the next row after that is equal. If it is not equal then stop. mysql user id time action 1 5 bought 1 5 purchased 1 5 sold 1 4 created Code: [Select] foreach($newsfeed as $k => $news) { if ($news['time'] == $news['time'] of $k--) { echo " you bought purchased and created"; } else { echo $news['action']; } } <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> </head> <?php // Connect to database================================================== include("connect_db.php"); // sending query =========================================================== $result = mysql_query("SELECT * FROM members Order By last") or die(mysql_error()); if (!$result) { die("Query to show fields from table failed"); } echo "<br />"; echo "<p>MEMBERS LIST</p>"; echo "<table border='10' cellpadding='3' cellspacing='2'>"; echo "<tr><th>First Name</th><th>Last Name</th>><th>Phone</th><th>Email</th></tr>"; // keeps getting the next row until there are no more to get ================ while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table ========================== echo "<tr><td>"; echo $row['first']; echo "</td><td>"; echo $row['last']; echo "</td><td>"; echo $row['phone']; echo "</td><td>"; echo $row['email']; echo "</td></tr>"; } echo "</table>"; ?> </body> </html> This is the output. MEMBERS LIST > First Last Phone Email data data data data ect............................................................... I cannot find where the > (greater than) sign is coming from. There is a space after MEMBERS LIST but I could not get it to work in this display. I have a long string of html, and what I want to do, if find all occurrences of: /static (anything after)... and replace with: http://www.mydomain.com/static (anything after). What is the best and fastest way to do this? Thanks. Anybody know why I'm getting "Please fill in all fields" error? I put comments in to make it easier Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Who's Missing?</title> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <h2>Someone Missing?</h2> <?php require_once('appvars.php'); require_once('connectvars.php'); if (isset($_POST['submit'])) { // Grab the score data from the POST $name = $_POST['name']; $partner_name = $_POST['partner_name']; $state = $_POST['state']; $photo = $_FILES['photo']['partner_name']; $photo_type = $_FILES['photo']['type']; $photo_size = $_FILES['photo']['size']; if (!empty($name) && !empty($partner_name) && !empty($state) && !empty($photo)) { if ((($photo_type == 'image/gif') || ($photo_type == 'image/jpeg') || ($photo_type == 'image/pjpeg') || ($photo_type == 'image/png')) && ($photo_size > 0) && ($photo_size <= GW_MAXFILESIZE)) { if ($_FILES['photo']['error'] == 0) { // Move the file to temp $target = GW_UPLOADPATH . $photo; if (move_uploaded_file($_FILES['photo']['tmp_name'], $target)) { // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // Write to the database $query = "INSERT INTO guitarwars VALUES (0, NOW(), '$name', '$partner_name', '$state', '$photo')"; mysqli_query($dbc, $query); // Confirm success with the user echo '<p>Partner added. Enjoy!</p>'; echo '<p><strong>Name:</strong> ' . $name . '<br />'; echo '<strong>Partner:</strong> ' . $partner_name . '<br />'; echo '<strong>State:</strong> ' . $state . '<br />'; echo '<img src="' . GW_UPLOADPATH . $photo . '" alt="Score image" /></p>'; echo '<p><a href="guitar.php"><< Back to Partners page</a></p>'; // Clear the data to clear the form $name = ""; $partner_name = ""; $state = ""; $photo = ""; mysqli_close($dbc); } else { echo '<p class="error">Sorry, there was a problem uploading your partners photo.</p>'; } } } else { echo '<p class="error">The photo must be a GIF, JPEG, or PNG image file no greater than ' . (GW_MAXFILESIZE / 320768) . ' MB in size.</p>'; } // delete the temporary photo image file @unlink($_FILES['photo']['tmp_name']); } else { echo '<p class="error">Please fill in all fields.</p>'; } } ?> <hr /> <form enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo GW_MAXFILESIZE; ?>" /> <label for="name">Name:</label> <input type="text" id="name" name="name" value="<?php if (!empty($name)) echo $name; ?>" /><br /> <label for="partner">Partner:</label> <input type="text" id="partner_name" name="partner_name" value="<?php if (!empty($partner_name)) echo $partner_name; ?>" /><br /> <label for="state">State:</label> <input type="text" id="state" name="state" value="<?php if (!empty($state)) echo $state; ?>" /><br /> <label for="photo">Photo:</label> <input type="file" id="photo" name="photo" /> <hr /> <input type="submit" value="Add Partner" name="submit" /> </form> </body> </html> I'm trying to write a piece that checks to see if something someone posts is a url or if it's just a url in a sentence. Basically, I want it so if someone puts in www.phpfreaks.com (then it does something) but if they put I am on www.phpfreaks.com where are you? (Then it does something else) Like the first one will get the dom of the page and post that, and the second one would just post the sentence with the url in it as a link. So I am getting my post $Post checking if there is a www or .com or .net or .gov in it $find2 = 'www.'; $find3 = '.com'; $find4 = '.net'; $find5 = '.gov'; if((strstr($Post, $find2) ==true)||(strstr($Post, $find3) ==true)||(strstr($Post, $find4) ==true)||(strstr($Post, $find5) ==true)){ then do I explode the whole thing, or what would I do in here with the $Post? some people might put in just phpfreaks.com others might put in http://www.phpfreaks.com and others might put in http://www.phpfreaks.com/forums/index.php?action=post;board=1.0 so I need to find the www. and or .com and find the first space before that, and after that and cut out the middle section, but I'm at a loss. } Hi There, I have ported my website over to another hosting provider and I cannot get this one thing working! We have images on our site, which this PHP Script should resize, but it can't find the Imagick.php script. I am convinced that it resides in a different path. Here is the error i get when trying to access one of the images : Warning: require_once(include/classes/Imagick.php) [function.require-once]: failed to open stream: No such file or directory in /hermes/bosweb/web128/b1282/ipg.accommodateruralcom/include/global.php on line 29 Fatal error: require_once() [function.require]: Failed opening required 'include/classes/Imagick.php' (include_path='.:/usr/local/lib/php-5.2.17/lib/php:/home/users/web/b1282/ipg.accommodateruralcom') in /hermes/bosweb/web128/b1282/ipg.accommodateruralcom/include/global.php on line 29 I contacted my hosting support about that and they said that the Imagick.php resides in the following directory : /usr/local/lib/ImageMagick I can appreciate that there may be references to this everywhere and anywhere. I have PHP files called imageResize, Global etc...just let me know which ones to post and ill do that. I really appreciate the help. [attachment deleted by admin] |