PHP - Swap Longitude And Latitude In A String
I have a string I am pulling out of a kml file to be used in google's static map image. The problem is that the longitude and latitude are in the wrong order.
$xml=simplexml_load_file($kml); //print_r($xml); $coordinates= $xml->Document->Placemark->Polygon->outerBoundaryIs->LinearRing->coordinates; $coordinates = str_replace(",0","|",$coordinates); echo $coordinates;$coordinates returns -93.93740385636626,32.5298698657008| -93.94147866742821,32.52989552832681| -93.94144945527509,32.53330102162547| -93.94975589137293,32.53335196474311| -93.94983123242544,32.52989370087431| -93.94493319136991,32.52989645540433| -93.9443121915328,32.52861950574362| -93.94419758821717,32.52736388060429| -93.94302907878635,32.52652644904565| -93.94229993303671,32.5257441308524| -93.94147580320451,32.52521094897828| -93.94137978713827,32.52261795379491| -93.93742258613195,32.5225916055261| -93.93740385636626,32.5298698657008| I need them as they are above separated by pipes to be used as a parameter in a url only I need the longitude and latitude swapped. So instead of "-93.93740385636626,32.5298698657008", I need it to read "32.5298698657008,-93.93740385636626". All of the coordinates I will be using in the future will be in the same general area as the locations above. Similar TutorialsHello im trying to write a simple latitude and longitude script for my game. So far i have a my users and locations tables set. I have in the users table 2 entries called latitude and longitude and also in locations table 2 entries called latitude and longitude. When player finishes registering and everything is ok i placed a $new_lat and had it choose a random number between 0 and 5. I did the same with $new_long had random choose a number between 0 and 5. Now i query the the locations table (after placing a few random latitude and longitude numbers between 0 and 5) and here is where im stumped. I need assign the latitudes and longitudes that are in the locations table into possibly 2 variables and then run a check to see if the random numbers chosen match and if they do keep doing new random numbers until the randomly chosen numbers do NOT match any those in the locations table. Can someone help me out with this? I have downloaded Post-Google-Maps plugin and it works great. But I would like to change the default latitude and longitude and can't figure out how. I have posted this question on their support site, but I haven't received an answer, and the site doesn't seem to be actively monitored. I'm hoping there is an easy solution, and that someone on this board can help me. The plugin contains two php pages. Here is the code from post-google-map.php. Code: [Select] <?php /* Plugin Name: Post Google Map Plugin URI: http://webdevstudios.com/support/wordpress-plugins/ Description: Plugin allows posts to be linked to specific addresses and coordinates and display plotted on a Google Map. Use shortcode [google-map] to display map directly in your post/page. Map shows plots for each post with filter options and preview when hovered. <a href="options-general.php?page=post-google-map/post-google-map.php">Plugin Settings</a> | Version: 1.5.1 Author: WebDevStudios.com Author URI: http://webdevstudios.com */ $gmp_version = "1.5.1"; //hook for adding admin menus add_action('admin_menu', 'gmp_menu'); //hook for adding a new address add_action('admin_menu', 'gmp_add_new_address'); //hook for post/page custom meta box add_action('admin_menu', 'gmp_meta_box_add'); //hook for add a map to the content add_filter('the_content', 'gmp_widget'); //hook for loading widget add_action('plugins_loaded', 'gmp_widget_init'); //save/update post/page address fields from meta box function gmp_add_new_address() { $gmp_submit = $_POST["gmp_submit"]; If (isset($gmp_submit) && !empty($gmp_submit) ) { post_meta_tags(); } } //add_action('edit_post', 'post_meta_tags'); //add_action('publish_post', 'post_meta_tags'); //add_action('save_post', 'post_meta_tags'); //add_action('edit_page_form', 'post_meta_tags'); function getWords($text, $limit) { $array = explode(" ", strip_tags($text), $limit+1); if (count($array) > $limit) { unset($array[$limit]); } return implode(" ", $array); } function gmp_widget_options() { //widget options form if ($_POST['gmp_form_submit']) { update_option('gmp_widget_title', esc_attr($_POST['gmp_widget_title']) ); } //load widget title $gmp_widget_title = get_option('gmp_widget_title'); ?> <div> <label for="cc_form_title"> <strong><?php _e('Title:'); ?></strong> </label> <input style="width: 100%; margin-bottom:1em;" id="gmp_widget_title" name="gmp_widget_title" type="text" value="<?php echo htmlspecialchars(stripslashes($gmp_widget_title)); ?>" /> Setting a title will override category tabs from displaying <input type="hidden" name="gmp_form_submit" value="Submit" /> </div> <?php } function gmp_widget_init() { //widget code if ( !function_exists('register_sidebar_widget') ) return; function gmp_widget_init2() { gmp_widget('xxx'); } function gmp_widget($content) { global $wpdb; global $post; $options_arr = get_option('gmp_params'); $key = $options_arr["post_gmp_params"]; $imgpath = WP_PLUGIN_URL . '/post-google-map/markers/'; $gmp_map_type = $options_arr["post_gmp_map_type"]; $gmp_cats = $options_arr["post_gmp_cats"]; $gmp_wordpress_loop = $options_arr["gmp_wordpress_loop"]; $gmp_categories = $options_arr["gmp_categories"]; $gmp_hide = $options_arr["gmp_hide"]; $gmp_marker_max = $options_arr["gmp_marker_max"]; $gmp_marker_order = $options_arr["gmp_marker_order"]; //random number for multiple map display srand ((double) microtime( )*1000000); $rn = rand( ); //print out default categories $CT="<div class='map_cats'>"; $cat=$_GET["cat"]; $iCat_ID=$_GET["map_cat_id"]; if (($iCat_ID=="") && ($cat!="")){ $iCat_ID=$cat; } if ($gmp_cats!= ""){ $Cat_Names = explode(",", $gmp_cats); for($i = 0; $i < count($Cat_Names); $i++){ $Cat_ID = $Cat_Names[$i]; $Cat = get_cat_name($Cat_ID); if (!is_single() && $iCat_ID==""){ //$iCat_ID=$Cat_ID; } if ($i!=0){ $CT.=" | "; } $CT.="<a "; if ($Cat_ID==$iCat_ID){ $CT.="style='font-weight:bold;'"; } $CT.="href=".add_query_arg("map_cat_id", $Cat_ID).">".$Cat."</a>"; } } $CT.="</div>"; $map="var map".$rn." = new GMap2(document.getElementById('map".$rn."'));"; $map.="map".$rn.".setCenter(new GLatLng(33.7877778,-117.8522222);"; $map.="map".$rn.".setUIToDefault();"; $map.="map".$rn.".setMapType(".$gmp_map_type.");"; $map.="var bounds".$rn." = new GLatLngBounds(33.7877778,-117.8522222); "; //if viewing a single post don't load plots by categories $x=1; //shortcode if ($content!="xxx") { $map_type="short_code"; include("get_map.php"); }else{ if ($iCat_ID==""){ $y=0; if (have_posts()) : while (have_posts()) : the_post(); include("get_map.php"); endwhile; endif; } if ($iCat_ID!="" || $y==0){ $recentPosts = new WP_Query(); $recentPosts->query('showposts='.$gmp_marker_max.'&cat='.$iCat_ID); while ($recentPosts->have_posts()) : $recentPosts->the_post(); include("get_map.php"); endwhile; } } $JS.="map".$rn.".setZoom(map".$rn.".getBoundsZoomLevel(bounds".$rn."));"; $JS.="map".$rn.".setCenter(bounds".$rn.".getCenter());"; $JS.="map".$rn.".zoomOut(); "; $JS = $map.$JS; $themap = '<li id="post-google-map" class="widget widget_gmp">'; //check if widget title exists, if so use it $gmp_widget_title = get_option('gmp_widget_title'); If ($gmp_widget_title != "") { $themap.='<h2 class="title">'.$gmp_widget_title.'</h2>'; }Else{ //display the category tabs instead $themap.=$CT; } $themap.="<script src='http://maps.google.com/maps?file=api&v=1&key=".$key."' type='text/javascript'></script>"; $themap.="<body onUnload='GUnload()'>"; if ($map_type=="short_code") { $themap.="<div id='map".$rn."' style='width:100%;height:400px;'></div>"; }Else{ $themap.="<div id='map".$rn."' style='width:100%;height:200px;'></div>"; } $themap.="<div id='map-info".$rn."'></div>"; $themap.="<script type='text/javascript'>"; $themap.=$JS; $themap.="var info".$rn." = document.getElementById('map-info".$rn."');"; $themap.="info".$rn.".innerHTML = '".str_replace('[google-map]', '', $Default_HTML)."';"; $themap.="</script>"; $themap.="</li>"; if ($map_type=="short_code") { return str_replace('[google-map]', $themap, $content); }else{ echo $themap; } } if ( function_exists('wp_register_sidebar_widget') ) // fix for wordpress 2.2.1 wp_register_sidebar_widget(sanitize_title('Post Google Map' ), 'Post Google Map', 'gmp_widget_init2', array(), 1); else register_sidebar_widget('Post Google Map', 'gmp_widget_init2', 1); register_widget_control('Post Google Map', 'gmp_widget_options'); } function gmp_meta_box_add() { // Check whether the 2.5 function add_meta_box exists before adding the meta box if ( function_exists('add_meta_box') ) { add_meta_box('gmp','Post Google Map','gmp','post'); add_meta_box('gmp','Post Google Map','gmp','page'); } } function del_gmp_address($deladdy) { //delete address from a post/page If (is_numeric($deladdy)) { $id = $_GET['post']; $gmp_arr = get_post_meta($id, 'gmp_arr', false); If (is_array($gmp_arr)) { delete_post_meta($id, 'gmp_arr'); unset($gmp_arr[$deladdy]); for ($row = 0; $row <= count($gmp_arr); $row++) { If (is_array($gmp_arr[$row])) { add_post_meta($id, 'gmp_arr', $gmp_arr[$row]); } } //echo "<div id=message class=updated fade>Address deleted successfully.</div>"; $isdeleted = true; } } } function post_meta_tags() { //verify user is on the admin dashboard and at least a contributor If ( is_admin() && current_user_can('level_1') ) { global $wpdb, $alreadyran; $gmp_id = $_POST["gmp_id"]; //if post not created yet create it if ($gmp_id==0){ $title=$_POST["post_title"]; $sql = "SELECT ID FROM ".$wpdb->prefix."posts order by ID desc LIMIT 1"; $rs = mysql_query($sql); if ($rs) { while ($r = mysql_fetch_assoc($rs)) { $gmp_id=$r['ID']; } } } //save the form data from the post/page meta box if (isset($gmp_id) && !empty($gmp_id) && $alreadyran != "1") { $id = $gmp_id; $alreadyran = "1"; //get post data $gmp_long = esc_attr($_POST["gmp_long"]); $gmp_lat = esc_attr($_POST["gmp_lat"]); $gmp_address1 = esc_attr($_POST["gmp_address1"]); $gmp_address2 = esc_attr($_POST["gmp_address2"]); $gmp_city = esc_attr($_POST["gmp_city"]); $gmp_state = esc_attr($_POST["gmp_state"]); $gmp_zip = esc_attr($_POST["gmp_zip"]); $gmp_marker = esc_attr($_POST["gmp_marker"]); $gmp_title = esc_attr($_POST["gmp_title"]); $gmp_description = esc_attr($_POST["gmp_description"]); $gmp_desc_show = esc_attr($_POST["gmp_desc_show"]); //get long & lat BRM if (isset($gmp_long) && !empty($gmp_long) && isset($gmp_lat) && !empty($gmp_lat)) { }elseif (isset($gmp_address1) && !empty($gmp_address1)){ $options_arr = get_option('gmp_params'); $key = $options_arr["post_gmp_params"]; //$key = get_option('post_gmp_params'); $addressarr = array($gmp_address1, $gmp_city, $gmp_state, $gmp_zip); $address = IMPLODE(",", $addressarr); $iaddress = "http://maps.google.com/maps/geo?q=".urlencode($address)."&output=csv&key=".$key.""; //$csv = file_get_contents($iaddress); //use the WordPress HTTP API to call the Google Maps API and get coordinates $csv = wp_remote_get($iaddress); $csv = $csv["body"]; $csvSplit = split(",", $csv); $status = $csvSplit[0]; $lat = $csvSplit[2]; $lng = $csvSplit[3]; if (strcmp($status, "200") == 0){ // successful $lat = $csvSplit[2]; $lng = $csvSplit[3]; } $gmp_long=$lat; $gmp_lat=$lng; } //create an array from the post data and long/lat from Google $gmp_arr=array( "gmp_long"=>$gmp_long, "gmp_lat"=>$gmp_lat, "gmp_address1"=>$gmp_address1, "gmp_address2"=>$gmp_address2, "gmp_city"=>$gmp_city, "gmp_state"=>$gmp_state, "gmp_zip"=>$gmp_zip, "gmp_marker"=>$gmp_marker, "gmp_title"=>$gmp_title, "gmp_description"=>$gmp_description, "gmp_desc_show"=>$gmp_desc_show, ); //save address array as option gmp_arr add_post_meta($id, 'gmp_arr', $gmp_arr); //echo "<div id=message class=updated fade>Address added successfully.</div>"; } } } function gmp() { global $post; //call function to delete an address If ($_GET['deladdy'] != "" && $isdeleted != true) { //verify user is at least a contributor and on the WP dashboard to allow deleting an address If ( is_admin() && current_user_can('level_1') ) { check_admin_referer('delete-address'); $deladdy = $_GET['deladdy']; del_gmp_address($deladdy); } } $post_id = $post; if (is_object($post_id)){ $post_id = $post_id->ID; } $options_arr = get_option('gmp_params'); $gmp_api_key = $options_arr["post_gmp_params"]; $gmp_arr = get_post_meta($post_id, 'gmp_arr', false); $imgpath = WP_PLUGIN_URL . '/post-google-map/markers/'; ?> <form method="post"> <input value="<?php echo $post_id; ?>" type="hidden" name="gmp_id" /> <?php If ($gmp_api_key == "") { ?> <div class="error"> <p> <strong> Google Maps API key has not been saved. <a href="<?php echo admin_url( 'options-general.php?page=post-google-map.php' ); ?>">Enter Google Maps API Key</a> to enable post mapping. </strong> </p> </div> <?php } ?> <div style="padding-bottom:10px;">Current Saved Addresses:</div> <table cellspacing="0" cellpadding="3" width="100%" style="margin-bottom:20px"> <tr> <td colspan="2"></td> <td><strong>Address 1</strong></td> <td><strong>Address 2</strong></td> <td><strong>City</strong></td> <td><strong>State</strong></td> <td><strong>Zip</strong></td> </tr> <?php If (is_array($gmp_arr)) { $bgc==""; for ($row = 0; $row < count($gmp_arr); $row++) { if($bgc==""){ $bgc="#eeeeee"; }else{\ $bgc=""; } $gmp_action = "delete-address"; ?> <tr style="background:<?php echo $bgc;?> !important;" bgcolor="<?php echo $bgc;?>"> <td><a title="Delete Address" href="<?php echo wp_nonce_url(add_query_arg ("deladdy", $row), $gmp_action); ?>"><img width="15px" border="0" src="<?php echo WP_PLUGIN_URL . '/post-google-map/delete.png';?>"></a></td> <td><img width="25px" src="<?php echo $imgpath.$gmp_arr[$row]["gmp_marker"]; ?>"></td> <td><?php echo $gmp_arr[$row]["gmp_address1"]; ?></td> <td><?php echo $gmp_arr[$row]["gmp_address2"]; ?></td> <td><?php echo $gmp_arr[$row]["gmp_city"]; ?></td> <td><?php echo $gmp_arr[$row]["gmp_state"]; ?></td> <td><?php echo $gmp_arr[$row]["gmp_zip"]; ?></td> </tr> <tr style="background:<?php echo $bgc;?> !important;" bgcolor="<?php echo $bgc;?>"> <td colspan="2"></td> <td colspan="5"> <?php echo $gmp_arr[$row]["gmp_title"]; if ($gmp_arr[$row]["gmp_description"]!=""){ echo " - "; } echo $gmp_arr[$row]["gmp_description"]; ?> </td> </tr> <?php } }Else{ ?><tr><td colspan="6" align="center"><i>no addresses saved</i></td></tr><?php } ?> </table> <div style="padding-bottom:10px;">Enter an address or coordinates to plot this post/page on a Google Map. You can enter multiple addresses</div> <table style="margin-bottom:20px"> <tr> <th style="text-align:right;" colspan="2"> </th> </tr> <tr> <th scope="row" style="text-align:right;"><?php _e('Marker') ?></th> <td> <select name="gmp_marker"> <?php $dir = WP_PLUGIN_DIR.'/post-google-map/markers/'; $x=0; if (is_dir($dir)){ if ($handle = opendir($dir)) { while (false !== ($file = readdir($handle))) { if ($file<>"."&&$file<>".."){ $x=1; echo "<option value='".$file."' style='background: url(".$imgpath.$file.")no-repeat;text-indent: 30px;height:25px;'>".$file; } } closedir($handle); } } ?> </select> </td> </tr> <tr> <th scope="row" style="text-align:right;"><?php _e('Title') ?></th> <td><input value="" type="text" name="gmp_title" size="25" tabindex=91 />*If blank will use post title.</td> </tr> <tr> <th valign="top" scope="row" style="text-align:right;"><?php _e('Description') ?></th> <td><textarea name="gmp_description" style="width:300px;" tabindex=92 ></textarea><br> <input checked type="checkbox" name="gmp_desc_show"> Use excerpt or first ten words of post if excerpt is blank. </td> </tr> <tr> <th scope="row" style="text-align:right;"><?php _e('Address 1') ?></th> <td><input value="" type="text" name="gmp_address1" size="25" tabindex=93 /></td> </tr> <tr> <th scope="row" style="text-align:right;"><?php _e('Address 2') ?></th> <td><input value="" type="text" name="gmp_address2" size="25" tabindex=94 /></td> </tr> <tr> <th scope="row" style="text-align:right;"><?php _e('City') ?></th> <td><input value="" type="text" name="gmp_city" size="25" tabindex=95 /></td> </tr> <tr> <th scope="row" style="text-align:right;"><?php _e('State') ?></th> <td><input value="" type="text" name="gmp_state" size="15" tabindex=96 /></td> </tr> <tr> <th scope="row" style="text-align:right;"><?php _e('Zip Code') ?></th> <td><input value="" type="text" name="gmp_zip" size="10" tabindex=97 /></td> </tr> <tr> <th scope="row" style="text-align:right;"></th> <td>OR</td> </tr> <tr> <th scope="row" style="text-align:right;"><?php _e('Longitude') ?></th> <td><input value="" type="text" name="gmp_long" size="20" tabindex=98 /></td> </tr> <tr> <th scope="row" style="text-align:right;"><?php _e('Latitude') ?></th> <td><input value="" type="text" name="gmp_lat" size="20" tabindex=99 /></td> </tr> <tr> <th scope="row"></th> <td> <div class="submit"> <input type="submit" name="gmp_submit" value="Add Address" tabindex=100 /><br>*Post title must exist to save address </div> </td> </tr> </table> </form> <?php } function gmp_menu() { add_options_page('Post Google Map Options', 'Post Google Map', 8, __FILE__, 'gmp_options'); } //Function to save the plugin settings function gmp_update_options() { check_admin_referer('gmp_check'); //create array for storing option values $wds_gmp_arr=array( "post_gmp_params"=>esc_attr($_POST['google_api_key']), "post_gmp_cats"=>esc_attr($_POST['gmp_cats']), "post_gmp_map_type"=>esc_attr($_POST['gmp_map_type']), "gmp_wordpress_loop"=>esc_attr($_POST['gmp_wordpress_loop']), "gmp_categories"=>esc_attr($_POST['gmp_categories']), "gmp_hide"=>esc_attr($_POST['gmp_hide']), "gmp_marker_max"=>esc_attr($_POST['gmp_marker_max']), "gmp_marker_order"=>esc_attr($_POST['gmp_marker_order']), ); //save array as option update_option('gmp_params', $wds_gmp_arr); } # gmp_update_options() function gmp_options() { global $gmp_version; # Acknowledge update if ( isset($_POST['update_gmp_options']) && $_POST['update_gmp_options'] ) { gmp_update_options(); echo "<div class=\"updated\">\n" . "<p>" . "<strong>" . __('Settings saved.') . "</strong>" . "</p>\n" . "</div>\n"; } //load plugin settings $options_arr = get_option('gmp_params'); $options = $options_arr["post_gmp_params"]; $options_cats = $options_arr["post_gmp_cats"]; $options_map_type = $options_arr["post_gmp_map_type"]; $gmp_wordpress_loop = $options_arr["gmp_wordpress_loop"]; $gmp_categories = $options_arr["gmp_categories"]; $gmp_hide = $options_arr["gmp_hide"]; $gmp_marker_max = $options_arr["gmp_marker_max"]; $gmp_marker_order = $options_arr["gmp_marker_order"]; echo '<div class="wrap">'; echo '<h2>' . __('Post Google Map Settings') . '</h2>'; echo 'You must have a Google Maps API Key for this plugin to work. '; echo '<form method="post" action="">'; if ( function_exists('wp_nonce_field') ) wp_nonce_field('gmp_check'); echo '<input type="hidden" name="update_gmp_options" value="1">'; echo '<p><b>Google API Key</b> '; echo '<input type="text"' . ' name="google_api_key" id="google_api[api_key]" size="100"' . ( $options['api_key'] ? 'value="'.$options.'"' : '' ) . ' />'; echo '<p>You can obtain a free Google Maps API Key he <a href="http://code.google.com/apis/maps/signup.html" target="_blank">http://code.google.com/apis/maps/signup.html</a></p>'; ?> <b>Default Map Settings</b> <table> <tr> <td align=right>Map Type:</td> <td> <select name="gmp_map_type"> <option value="G_NORMAL_MAP" <?php If ($options_map_type == "G_NORMAL_MAP") { echo "SELECTED"; }?>>Map <option value="G_SATELLITE_MAP" <?php If ($options_map_type == "G_SATELLITE_MAP") { echo "SELECTED"; }?>>Satellite <option value="G_HYBRID_MAP" <?php If ($options_map_type == "G_HYBRID_MAP") { echo "SELECTED"; }?>>Hybrid <option value="G_DEFAULT_MAP_TYPES" <?php If ($options_map_type == "G_DEFAULT_MAP_TYPES") { echo "SELECTED"; }?>>Terrain <option value="G_PHYSICAL_MAP" <?php If ($options_map_type == "G_PHYSICAL_MAP") { echo "SELECTED"; }?>>Physical </select> </td> </tr> <!--<tr> <td valign="top" align=right>Marker View:</td> <td> <input type="checkbox" name="gmp_wordpress_loop" value="1" <?php if ($gmp_wordpress_loop==1){ ?>checked<?php } ?>>WordPress Loop <input type="checkbox" name="gmp_categories" value="1" <?php if ($gmp_categories==1){ ?>checked<?php } ?>>Categories<br>*if both are checked map will show categories if loop is empty. </td> </tr> <tr> <td align="right"></td> <td> <input type="checkbox" name="gmp_hide" value="1" <?php if ($gmp_hide==1){ ?>checked<?php } ?>>Hide map if ever empty. </td> </tr>--> <tr> <td align="right" valign="top">Category Tabs:</td> <td valign="top"> <input type="text" name="gmp_cats" value="<?php echo $options_cats; ?>">*Category IDs(ie 1,2,3) </td> </tr> <tr> <td align=right>Marker Plot Max:</td> <td> <select name="gmp_marker_max"> <?php for ($x = 0; $x <50;){ $x=$x+5; ?> <option value='<?php echo $x?>' <?php if ($gmp_marker_max==$x){ ?>selected<?php } ?>><?php echo $x?> <?php } ?> </select> *per page load </td> </tr> <!--<tr> <td align="right">Marker Order:</td> <td> <?php echo $gmp_marker_order;?> <input type="radio" name="gmp_marker_order" value="Newest" checked>Newest <input type="radio" name="gmp_marker_order" value="Random" <?php if ($gmp_marker_order=="Random"){ ?>checked<?php } ?>>Random </td> </tr>--> </table> <?php echo '<p class="submit">' . '<input type="submit"' . ' value="' . attribute_escape(__('Save Changes')) . '"' . ' />' . '</p></form>'; echo '<p>For support please visit our <a href="http://webdevstudios.com/support/wordpress-plugins/" target="_blank">WordPress Plugins</a> and <a href="http://webdevstudios.com/support/forum/" target="_blank">Support Forum</a><br>Version '. $gmp_version .' by <a href="http://webdevstudios.com/" title="WordPress Development and Design" target="_blank">WebDevStudios.com</a> | <a href="http://twitter.com/webdevstudios" target="_blank">WDS on Twitter</a></p>'; echo '</div>'; } function gmp_get_post_image($post_id, $width=0, $height=0) { $dimensions = ""; $post_id = explode(",", $post_id); foreach ($post_id as $id) { $my_query = new WP_Query('p='.$id); while ($my_query->have_posts()) : $my_query->the_post(); $attargs = array( 'numberposts' => 1, 'order' => 'ASC', 'orderby' => 'menu_order', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'post_parent' => $id); $attachments = get_children($attargs); if ($attachments) { foreach ($attachments as $attachment) { If ($width != "full" && $width != "medium" && $width != "thumb" && $width != "large") { return wp_get_attachment_image($attachment->ID, array($width, $height), false); }Else{ return wp_get_attachment_image($attachment->ID, $width, false); } } } endwhile; } } // Install/Uninstall Plugin register_activation_hook(__FILE__,'gmp_install'); //register_deactivation_hook(__FILE__,'gmp_uninstall'); //coming soon function gmp_install () { //load settings option array $options_arr = get_option('gmp_params'); //check if settings array is set //if not we need to upgrade the settings to the new array If (!is_array($options_arr) ) { //load current settings $key = get_option('post_gmp_params'); $gmp_map_type = get_option('post_gmp_map_type'); $gmp_cats = get_option('post_gmp_cats'); $gmp_wordpress_loop = get_option('gmp_wordpress_loop'); $gmp_categories = get_option('gmp_categories'); $gmp_hide = get_option('gmp_hide'); $gmp_marker_max = get_option('gmp_marker_max'); $gmp_marker_order = get_option('gmp_marker_order'); //create array for storing option values with current settings $wds_gmp_arr=array( "post_gmp_params"=>esc_attr($key), "post_gmp_cats"=>esc_attr($gmp_cats), "post_gmp_map_type"=>esc_attr($gmp_map_type), "gmp_wordpress_loop"=>esc_attr($gmp_wordpress_loop), "gmp_categories"=>esc_attr($gmp_categories), "gmp_hide"=>esc_attr($gmp_hide), "gmp_marker_max"=>esc_attr($gmp_marker_max), "gmp_marker_order"=>esc_attr($gmp_marker_order), ); //save array as option update_option('gmp_params', $wds_gmp_arr); //delete original settings delete_option('post_gmp_params'); delete_option('post_gmp_map_type'); delete_option('post_gmp_cats'); delete_option('gmp_wordpress_loop'); delete_option('gmp_categories'); delete_option('gmp_hide'); delete_option('gmp_marker_max'); delete_option('gmp_marker_order'); } } ?> Here is the code from get-map.php. Code: [Select] <?php //code to generate Google Map $post_id = $post; if (is_object($post_id)){ $post_id = $post_id->ID; $title=get_the_title($post_id->ID); $link=get_permalink($post_id->ID); } //echo "$post_id".$post_id; $gmp_arr = get_post_meta($post_id, 'gmp_arr', false); If (is_array($gmp_arr)) { for ($row = 0; $row < count($gmp_arr); $row++) { $y=$y+1; $html="<table width=100%><tr>"; $iTitle=esc_attr($gmp_arr[$row]["gmp_title"]); $iDesc=$gmp_arr[$row]["gmp_description"]; $iDesc_Show=$gmp_arr[$row]["gmp_desc_show"]; if ($iTitle==""){ $iTitle=$title; } $html.="<td colspan=2 valign=top><b><a href=".$link.">".$iTitle."</a></b>"; if ($iDesc=="" && $iDesc_Show=="on"){ if ($ran!=1){ $query = "SELECT post_excerpt,post_content FROM wp_posts WHERE ID = " . $post_id; $result = $wpdb->get_results($query, ARRAY_A); $excerpt = $result[0]['post_excerpt']; $icontent = $result[0]['post_content']; //clean up desc $icontent = esc_attr($icontent); $ran=1; } $iDesc=$excerpt; if ($iDesc==""){ $iDesc=getWords($icontent, 5); } } if ($iDesc!=""){ //echo $iDesc."<br>"; $iDesc = esc_attr($iDesc); //echo $iDesc; $html.="<br>".$iDesc; } $html.="</td></tr><tr>"; $thumb=gmp_get_post_image($post_id, 60); if ($thumb!=""){ $html.= "<td><a href=".$link.">".$thumb."</a></td>"; } $html.="<td valign=top>".$gmp_arr[$row]["gmp_address1"]."<br>".$gmp_arr[$row]["gmp_city"]." ".$gmp_arr[$row]["gmp_state"]." ".$gmp_arr[$row]["gmp_zip"]."</td></tr></table>"; //set markers if coords exist if (($gmp_arr[$row]["gmp_long"]!="") && ($gmp_arr[$row]["gmp_lat"]!="")){ $x=$x+1; $JS.="var point".$rn." = new GPoint(".$gmp_arr[$row]["gmp_lat"].", ".$gmp_arr[$row]["gmp_long"].");"; $JS.="var icon".$rn." = new GIcon();"; $JS.="icon".$rn.".image = '".$imgpath.$gmp_arr[$row]["gmp_marker"]."';"; $JS.="icon".$rn.".iconAnchor = new GPoint(15, 35);"; $JS.="var marker".$rn."".$x." = new GMarker(point".$rn.",icon".$rn.");"; $JS.="GEvent.addListener(marker".$rn."".$x.", 'click', function() {"; //$JS.="map.openInfoWindowHtml(marker".$x.".getPoint(), html".$x.");"; $JS.="location.href='".$link."';"; $JS.="});"; $JS.="GEvent.addListener(marker".$rn."".$x.", 'mouseover', function() {"; $JS.="var info".$rn." = document.getElementById('map-info".$rn."');"; $JS.="info".$rn.".innerHTML = '".str_replace('[google-map]', '', $html)."';"; if ($bm==""){ $Default_HTML=$html; $bm=1; } $JS.="});"; $JS.="map".$rn.".addOverlay(marker".$rn."".$x.");"; $JS.="bounds".$rn.".extend(marker".$rn."".$x.".getPoint());"; } } } ?> Is there something on either of these pages that I can change? Thanks so much for all your help. Hi All I've a huge database of addresses and I need to convert them to Latitude and Longtitude to enable me to do some geopositioning and distances etc. I've tried the following code, but just get a blank result Code: [Select] <?php $address="high+street+leicester+england"; $url = 'http://maps.google.com/maps/geo?q='.$address.'&output=json&oe=utf8&sensor=false&key='.$api_key; $data = @file_get_contents($url); $jsondata = json_decode($data,true); if(is_array($jsondata )&& $jsondata ['Status']['code']==200){ $lat = $jsondata ['Placemark'][0]['Point']['coordinates'][0]; $lon = $jsondata ['Placemark'][0]['Point']['coordinates'][1]; } echo "hello".$lat . " " . $lon; in my php.ini Code: [Select] ; Whether to allow the treatment of URLs (like http:// or ftp://) as files. allow_url_fopen = On ; Whether to allow include/require to open URLs (like http:// or ftp://) as files. allow_url_include = On Any ideas? Hi, I am trying to make some adjustments to uploadify.php which comes with the latest version of uploadify (3.0 beta), so that it works with a session variable that stores the login username and adds it to the path for uploads. Here is uploadify.php as it currently looks: Code: [Select] <?php session_name("MyLogin"); session_start(); $targetFolder = '/songs/' . $_SESSION['name']; // Relative to the root if (!empty($_FILES)) { $tempFile = $_FILES['Filedata']['tmp_name']; $targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder; $targetFile = rtrim($targetPath,'/') .'/'. $_FILES['Filedata']['name']; // Validate the file type $fileTypes = array('m4a','mp3','flac','ogg'); // File extensions $fileParts = pathinfo($_FILES['Filedata']['name']); if (in_array($fileParts['extension'],$fileTypes)) { move_uploaded_file($tempFile,$targetFile); echo '1'; } else { echo 'Invalid file type.'; } } echo $targetFolder; ?> I added Code: [Select] echo $targetFolder; at the bottom so that I could make sure that the string returned was correct, and it is, i.e. '/songs/nick'. For some reason though, uploads are not going to the correct folder, i.e. the username folder, but instead are going to the parent folder 'songs'. The folder for username exists, with correct permissions, and when I manually enter Code: [Select] $targetFolder = '/songs/nick';all works fine. Which strikes me as rather strange. I have limited experience of using php, but wonder how if the correct string is returned by the session variable, the upload works differently than with the manually entered string. Any help would be much appreciated. It's the last issue with a website that was due to go live 2 days ago! Thanks, Nick Hello, Can I set the priority on my scripts relating to swap? Something like set_swap(10); would mean that it will be first to go into swap and set_swap(1) means it will go as a last resort and set_swap(5) being the default ? Kind of like the proc_nice() but for memory ? Thanks, David This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=326004.0 Hey there, Thanks for taking the time to read my thread. My issue is that I can't think of a way to edit a XML file using PHP's XML functionality and then assign the edited contents to a string instead of saving the file. Because my issue is that I have to edit the XML file based upon a string brought from a remote location then give it back to that remote location using a string again, to be exact I am doing it via Linux command line utilizing SSH2. This is what I managed to complete on my own. function CheckIVMPConfig($ServerID) { global $Panel; if(is_numeric($ServerID) && $this->IsValidServer($ServerID)) { // We select the game server that the FTP account was created for. $Servers = mysql_query("SELECT * FROM control_servers WHERE server_id = '".mysql_real_escape_string($FTPAccount['ftp_server'])."'"); $Server = mysql_fetch_array($Servers); // Here we select the Box ID that the game server is on. $Boxs = mysql_query("SELECT * FROM control_machines WHERE machine_id = '".$Server['server_machine']."'"); $Box = mysql_fetch_array($Boxs); // Now we select the required package for the box. $Packages = mysql_query("SELECT * FROM control_packages WHERE package_id = '".$Server['server_package']."'"); $Package = mysql_fetch_array($Packages); // Retrive the file. $Config = $CProtocol->exec("cat /home/{$Server['server_id']}/{$Package['package_config']}"); $Parse = SimpleXMLElement($Config); foreach($Parse as $Entry) // loop through our books { if($Entry->port != $Server['server_port']) { // edit the value } else if($Entry->maxplayers > $Server['server_slots']) { // edit the value } } } } Hello all, I'm trying to change the end of a javascript call based on the end of the url string. The common part of all the url strings is sobi2Id=, I'm trying to do this with strstr but am having no luck. I'm new to php so my syntax knowledge is terrible! at the moment i've got Code: [Select] <?php $url = $_SERVER['REQUEST_URI']; $tag = strstr ($url, 'sobi2Id='); echo $tag; ?> but this returns an unexpected T_STRING, expecting ',' or ';' Can anyone debug this? I may well be being really silly! Hi,
In my code i am fetching row per row out of my database through
->fetch(PDO::FETCH_ASSOC)this fetch have i put in a WHILE loop to fetch all the rows, one at a time while($select_rma_row = $select_rma_detail->fetch(PDO::FETCH_ASSOC)){In my array $select_rma_row there are a lot of value's that are (int) 1 and i really want to echo them as "YES" (1 = YES) What is the best way to change every (int) 1 to "YES" in that array? also is there a whay i can call every $key inside that array? Like you do with a foreach i.e. : if $select_rma_row[$key] == 1 { $select_rma_row[$key] == "YES"; }Thank you! Edited by Raz3rt, 21 May 2014 - 09:30 AM. Hi guys, I have written a page that contains a form. When the user chooses a color, it is posted, then the posted value is re-written as a filename, sent through a function, and the image on the page uses the "colorized.gif" created by the function to make an image swap "onclick. Problem is, no matter the choice, it always changes the picture to orange! Here is the code for the form: <?php include('function.php'); ?> <!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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>PHP GD CONFIGURATOR</title> </head> <body> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> Red<input type="radio" name="color" value="red" /> Orange<input type="radio" name="color" value="orange" /> Ivory<input type="radio" name="color" value="ivory" /> Black<input type="radio" name="color" value="black" /> <input type="submit" name="submit" value="submit" /> </form> <?php if($_POST['color'] != NULL){ echo $_POST['color']; $file =('gdimages/' . $_POST['color'] . '.gif'); createImg($file); } ?> <img src="default.jpg" name="lola" alt="lola dining chair" onclick="this.src = 'colorized.gif'" /> </body> </html> And here is the function... function createImg ($imgname1) { $base = imagecreatefromgif("gdimages/base.gif"); $top = imagecreatefromgif($imgname1); if ($top) { imagecopy($base, $top, 0, 0, 0, 0, 250, 250); imagejpeg($base, 'colorized.gif'); imagedestroy($base); } else{ header("Content-Type: text/html"); } } I really can't understand it...this is my first attempt at programming something new by myself...and I really need it to work!!! I also plan for this to work with combining more than 2 images from more than two choice menus...so debugging now is definitely necessary. Any suggestions? I have some code that displays 1 large image and then 5 small ones, you click on a small one and it becomes the large one "trades places" I then fixed the sizes so they don't distort when changing from large to small and then back. My problem is when the image is clicked the large image size does not change, the image does I that my issue lies here Code: [Select] <img name='picture' src=uploads/harkly_1.jpg ";echo imageResize($myImg1[0], $myImg1[1], 300); echo " border=0></td> but no clue on how to fix it this part Quote $myImg1[0], $myImg1[1 needs to change based on the selected image, can someone help me figure out how to make this happen?? Is there someway to create an if statement for this? Code: [Select] If (something){ echo "$myImg1[0], $myImg1[1]"; } else { echo "$myImg2[0], $myImg2[1]"; } My full code Code: [Select] <?php // to change the image size within the web page function imageResize($width, $height, $target) { //takes the larger size of the width and height and applies the formula accordingly... //this is so this script will work dynamically with any size image if ($width > $height) { $percentage = ($target / $width); } else { $percentage = ($target / $height); } //gets the new value and applies the percentage, then rounds the value $width = round($width * $percentage); $height = round($height * $percentage); //returns the new sizes in html image tag format... //this is so you can plug this function inside an image tag and just get the return "width='$width' height='$height'"; } ?> <HEAD> <SCRIPT LANGUAGE="JavaScript"> <!-- Original: Ronnie T. Moore, Editor --> <!-- Web Site: The JavaScript Source --> <!-- Begin var photo_1 = new Image(); var photo_2 = new Image(); var photo_3 = new Image(); photo_1.src = "uploads/harkly_1.jpg"; photo_2.src = "uploads/harkly_2.jpg"; photo_3.src = "uploads/harkly_3.jpg"; function doButtons(picimage) { eval("document['picture'].src = " + picimage + ".src"); } // End --> </script> </HEAD> <?php //get the image size of the picture and load it into an array $photo_1="uploads/harkly_1.jpg"; $photo_2="uploads/harkly_2.jpg"; $photo_3="uploads/harkly_3.jpg"; $myImg1 = getimagesize($photo_1); $myImg2 = getimagesize($photo_2); $myImg3 = getimagesize($photo_3); echo " <BODY> <center> <table border=1> <tr><td> <p> <li><a href = '' onmouseover = \"doButtons('photo_1')\"><img name='photo_1' src='$photo_1' ";echo imageResize($myImg1[0], $myImg1[1], 55); echo " border=0><p> <li><a href = '' onmouseover = \"doButtons('photo_2')\"><img name='photo_2' src='$photo_2' ";echo imageResize($myImg2[0], $myImg1[1], 55); echo " border=0><p> <li><a href = '' onmouseover = \"doButtons('photo_3')\"><img name='photo_3' src='$photo_3' ";echo imageResize($myImg3[0], $myImg1[1], 55); echo " border=0><p> <td width=440 height=300> <img name='picture' src=uploads/harkly_1.jpg ";echo imageResize($myImg1[0], $myImg1[1], 300); echo " border=0></td> </tr> </table> </center> "; ?> hey guys im trying to find a string inside a string which could be made up of different things eg... {$test}, {$test1}, {$test2} etc (but the varable inside could be called anything hence maybe using regex im not sure?) is this possible?...i hope you guys understand....thanks I have the following function, which takes a string with commas in it and attempts remove those commas. The way I have it here is that I use explode to take out the commas, which makes an array, and then iterate through that array to put a string back together without the commas. function tags_to_sort_by( $sortMeta ) { $sortByArray = explode(",", $sortMeta); $sortByCount = count($sortByArray); for ($i = 0; $i < $sortByCount; $i++) { $sortByString += $sortByArray[$i]; } return $sortByString; } What does not work is the following line: $sortByString += $sortByArray[$i]; Somehow that outputs a 0, which I don't understand. It should output something like: arrayItem1 arrayItem2 array3 etc. My question is if there either is an easier way to remove the commas from the original string or what I am doing wrong in this line: $sortByString += $sortByArray[$i]; // I am trying to concatenate each part of the array back into the string. Thanks a lot for help with this!
In PHP Version 8.0 shows error as : In previous versions of PHP it does not show any error. Please resolve the issue. Ok... I had typed this post out ONCE already and when I clicked REFRESH IMAGE to get a diff captcha it ERASED MY POST LMAO this is not my night.... What I need help with is probably more simple then I can even think right now - ive been digging at this for 3 hrs now and im out of time for the night I have a DB Record storing ID's between PIPES | when the initial entry is made in DB it stores it like so |47| NOTE: the number could be different these are ID's number doesnt matter its just between Pipes When the second entry is added its added like so |47||67| say we have a total of 5 Entries |47||67||82||55||69| I need to find ID 82 in that string and it has to be between Pipes Find 82 in data between | and return that ID 82 I am putting between pipes because the ID's can be duplicate digits in different lengths so say I have 8 as my ID and down the string i have another id as 88 -- I cant possibly find the correct ID without some sort of seperation character so i used Pipes soo my end goal is the ability to search and if true or false do action if ($result == $find_id){ echo "ID is there"; }else{ echo "NOT THERE -- Adding it"; } Any help is appreciated guys Thanks SangrelX I need to know if a string exists within a string. I've tried using STRIPOS() but it returns zero or false if what I'm looking for is the first part of the string. I don't care what function I use, but I need to get a "true" when the needle string is present anywhere in the haystack string, even at location zero. Is there some way to set up the STRIPOS() statement? I've tried: if ((stripos($title, 'needle') > 0 ) if ((stripos($title, 'needle') = true ) and even if ((stripos($title, 'needle') >= 0 ) which returns true for everything, even when the needle string is NOT present. Any help appreciated. thanks, Tom I am looking for a date within larger string, lets say the date is December 4, 2010. To find it I use pattern and function below: $Pattern='/[(January|February|March|April|May|June|July|August|September|October|November|December)] \d, \d\d\d\d/i'; preg_match_all($Pattern, $String, $Matches, PREG_OFFSET_CAPTURE, $NumberPosition); The function finds the dates within the string but to my supprise the result I get in $Matches is: r 4, 2010 What I would like to get is: December 4, 2010 but don't know how it should be fixed. I thought that with the pattern I am using but obviously that is not the case. |