[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 552
  • Last Modified:

php variable echo'ed out puts a / in front of an apostrophe

I am working on a wordpress theme with custom options and one of the options is for the header text.  The variable works and so does the code but when I put a name that includes an apostrophe it puts a "/" in front of it.  Can anyone tell me why it is doing this and how to stop it.

Here is the site I am working on...
0
divahomemaker
Asked:
divahomemaker
  • 4
  • 3
2 Solutions
 
Dave BaldwinFixer of ProblemsCommented:
Sure it's not putting a backslash '\' instead?  That would be to 'escape' the apostrophe aka single quote.  Sometimes you have to use stripslashes() to remove it.  More info here: http://us3.php.net/manual/en/function.stripslashes.php
0
 
Ray PaseurCommented:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_6630-Magic-Quotes-a-bad-idea-from-day-one.html

If that article does not answer the question, please post back and show us some test data, thanks, ~Ray
0
 
divahomemakerAuthor Commented:
I "tried" using both of these.  Not really sure what I am doing.  I did check the .phpini file and the magic quotes are already turned off.  I tried to put the action code from Ray_Paseur and it gave me an error?  I am using Wordpress and the functions.php file.  I really need a little more instruction on where to put these codes.
0
Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

 
Ray PaseurCommented:
It's possible that the escape characters have already polluted the data base.  If magic quotes was ever on at all, this may be a risk.  Do you have phpMyAdmin installed?  It will let you look directly into the data base so you can see whether this has happened.
0
 
divahomemakerAuthor Commented:
I do have phpMyAdmin... From what I am reading online, it is due to Wordpress looking for Magic quotes and then adding them back in.  So I need to remove them with the data that is being $_Post .. Here is the functions.php code.  I am specifically working on the "unit name" section.  That is where they can input the unit name in the theme options page and it will populate it into the index.php page.

<?php
	// Add RSS links to <head> section
	automatic_feed_links();
	
	// Load jQuery
	if ( !is_admin() ) {
	   wp_deregister_script('jquery');
	   wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"), false);
	   wp_enqueue_script('jquery');
	}
	
	// Clean up the <head>
	function removeHeadLinks() {
    	remove_action('wp_head', 'rsd_link');
    	remove_action('wp_head', 'wlwmanifest_link');
    }
    add_action('init', 'removeHeadLinks');
    remove_action('wp_head', 'wp_generator');

//Register right sidebar
    if (function_exists('register_sidebar')) {
    	register_sidebar(array(
    		'name' => 'Header Widgets',
    		'id'   => 'header-widgets',
    		'description'   => 'These are widgets for the header.',
    		'before_widget' => '<div id="%1$s" class="widget %2$s">',
    		'after_widget'  => '</div>',
    		'before_title'  => '<h2>',
    		'after_title'   => '</h2>'
    	));
    }	

//Register left sidebar
    if (function_exists('register_sidebar')) {
    	register_sidebar(array(
    		'name' => 'Left Sidebar Widgets',
    		'id'   => 'left sidebar-widgets',
    		'description'   => 'These are widgets for the left sidebar.',
    		'before_widget' => '<div id="%1$s" class="widget %2$s">',
    		'after_widget'  => '</div>',
    		'before_title'  => '<h2>',
    		'after_title'   => '</h2>'
    	));
    }

//Register mid sidebar
    if (function_exists('register_sidebar')) {
    	register_sidebar(array(
    		'name' => 'Middle Widgets on Homepage',
    		'id'   => 'middle-widgets',
    		'description'   => 'These are widgets in the middle of the homepage.',
    		'before_widget' => '<div id="%1$s" class="widget %2$s">',
    		'after_widget'  => '</div>',
    		'before_title'  => '<h2>',
    		'after_title'   => '</h2>'
    	));
    }
	
//Register right sidebar
    if (function_exists('register_sidebar')) {
    	register_sidebar(array(
    		'name' => 'Right Sidebar Widgets',
    		'id'   => 'right-sidebar-widgets',
    		'description'   => 'These are widgets for the right sidebar.',
    		'before_widget' => '<div id="%1$s" class="widget %2$s">',
    		'after_widget'  => '</div>',
    		'before_title'  => '<h2>',
    		'after_title'   => '</h2>'
    	));
    }
	
//Register right sidebar
    if (function_exists('register_sidebar')) {
    	register_sidebar(array(
    		'name' => 'Footer Widgets',
    		'id'   => 'footer-widgets',
    		'description'   => 'These are widgets for the footer.',
    		'before_widget' => '<div id="%1$s" class="widget %2$s">',
    		'after_widget'  => '</div>',
    		'before_title'  => '<h2>',
    		'after_title'   => '</h2>'
    	));

if (get_option('YBA_Theme_1')) {
	$theme_options=get_option('YBA_Theme_1');
} else {
	add_option('YBA_Theme_1' , array (
	'unit_text' => 'Awesome Unit'
	));
}


//Add Theme Options Page
add_action ('admin_menu', 'theme_page_add');
function theme_page_add () {
	add_menu_page ('themes.php','Design Options', 8, 'themeoptions', 'theme_page_options');
}
function theme_page_options () {
	
	global $theme_options;
	
	$new_values = array (
		'unit_text' => htmlentities($_POST['unit_text'], ENT_QUOTES)
	);		
	
	update_option('YBA_Theme_1', $new_values);
	
	$theme_options= $new_values;

	echo '<div class="wrap">';
	echo '<h2>Design Options</h2>';
?>
<form action="themes.php?page=themeoptions" method="post">
<label for="unit_text">Unit Name: </label><input name="unit_text" id="unit_text" value="<?php echo $theme_options['unit_text']; ?>" />
<br />
<input type="submit" value="Update Design Options" name="submit" />
</form>

<?php
echo '</div>';
}

//Options for Theme	
register_default_headers( array (
 'Logo' => array (
 'url' => '%s/images/headers/logo.png',
 'thumbnail_url' => '%s/images/headers/logo.png',
 'description' => __( 'logo', 'YBATheme1' )
 )
 ) );
	
 }

add_action( 'after_setup_theme', 'padd_theme_header_setup' );
 
if ( ! function_exists('padd_theme_header_setup') ):
 function padd_theme_header_setup() {
 add_theme_support( 'post-thumbnails' );
 define( 'HEADER_IMAGE', '%s/images/headers/logo.png' );
 define( 'HEADER_IMAGE_WIDTH', apply_filters( 'YBA-Theme-1', 265 ) );
 define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'YBA-Theme-1', 310 ) );
 set_post_thumbnail_size( HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true );
 define( 'NO_HEADER_TEXT', true );
 add_custom_image_header( '', 'padd_theme_header_img_style' );

register_default_headers( array (
 'logo' => array (
 'url' => '%s/images/headers/logo.png',
 'thumbnail_url' => '%s/images/headers/logo.png',
 'description' => __( 'Logo', 'YBA-Theme-1' )
 )
 ) );
 }
 endif;
 
if ( ! function_exists( 'padd_theme_header_img_style' ) ) :
 function padd_theme_header_img_style() {
 ?>

<style type="text/css">
   	#header-img {
   		height: <?php echo HEADER_IMAGE_HEIGHT; ?>px;
  		width: <?php echo HEADER_IMAGE_WIDTH; ?>px;
   	}
 	#header-img img {
 		border: 0;
 		padding: 0;
 	}
 	#header-img h1, #header-img #desc {
 		display: none;
 	}
 </style>

<?php
}
endif;
 ?>

Open in new window

.
0
 
Ray PaseurCommented:
Is this where the slashes are showing up?  If so, maybe the change shown here will help.  I am not at all sure about this, but it's worth a try since it is so easy to test.

<form action="themes.php?page=themeoptions" method="post">
<label for="unit_text">Unit Name: </label><input name="unit_text" id="unit_text" value="<?php echo stripslashes($theme_options['unit_text']); ?>" />
<br />
<input type="submit" value="Update Design Options" name="submit" />
</form>

Open in new window

0
 
divahomemakerAuthor Commented:
Thanks Ray_Paseur.... It works!

But I also had to add it in one other place in case someone finds this and is trying to fix their pages.

This is the way the options page works.... There is a form (the piece of code you edited above) that asks them what they want the unit name to be.  When they enter it, it stores in that page so when they come back to change the name. it shows them the current name in the form box.

Then, once they enter a name into the form, it goes to header.php via this code,
<div class="unit_name"> <?php $theme_options = get_option('YBA_Theme_1'); echo stripslashes ($theme_options['unit_text']); ?></div>

Open in new window


and shows the unit name they entered at the top of the page in a <div>

So as you see above I just added the stripslashes the same way that you did it in the other code and that way it works on both the form side AND the website side.  

Thank you SO much!
0
 
Ray PaseurCommented:
Glad that did the trick!  Thanks for the points, ~Ray
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now