Skip to main content
improved answer to actually be an answer
Source Link
Romans-8---31-39
  • 2.9k
  • 1
  • 15
  • 20

Try using the php function addslashes:

<?php
$str = "Is your name O'reilly?";

// Outputs: Is your name O\'reilly?
echo addslashes($str);
?>

So for EE you could have something like:

(UPDATE 1: the following does not work:)

<p>This is the title and excerpt of this entry: "
    <?php 
        $str = "<strong>". addslashes({title}) . "</strong> : ";
        $str .= addslashes({post_excerpt}); // combine title and post_excerpt
        echo  stripslashes($str); // remove the slashes.
    ?>
"</p>

UPDATE 1 the following does work:

Following the suggestion of th3mus1cman above, this does work in a plugin without needing addslashes:

On your template:
<p>This is the excerpt of this entry: "
                    
    {exp:test_php}{post_excerpt}{/exp:test_php}

"</p>

In your test_php plugin: 
public function __construct()
{
    $ee_str = ee()->TMPL->tagdata;
    $new_str = "<strong>". $ee_str . "</strong>";
    
    $this->return_data = $new_str;
}

Try using the php function addslashes:

<?php
$str = "Is your name O'reilly?";

// Outputs: Is your name O\'reilly?
echo addslashes($str);
?>

So for EE you could have something like:

<p>This is the title and excerpt of this entry: "
    <?php 
        $str = "<strong>". addslashes({title}) . "</strong> : ";
        $str .= addslashes({post_excerpt}); // combine title and post_excerpt
        echo  stripslashes($str); // remove the slashes.
    ?>
"</p>

Try using the php function addslashes:

<?php
$str = "Is your name O'reilly?";

// Outputs: Is your name O\'reilly?
echo addslashes($str);
?>

So for EE you could have something like:

(UPDATE 1: the following does not work:)

<p>This is the title and excerpt of this entry: "
    <?php 
        $str = "<strong>". addslashes({title}) . "</strong> : ";
        $str .= addslashes({post_excerpt}); // combine title and post_excerpt
        echo  stripslashes($str); // remove the slashes.
    ?>
"</p>

UPDATE 1 the following does work:

Following the suggestion of th3mus1cman above, this does work in a plugin without needing addslashes:

On your template:
<p>This is the excerpt of this entry: "
                    
    {exp:test_php}{post_excerpt}{/exp:test_php}

"</p>

In your test_php plugin: 
public function __construct()
{
    $ee_str = ee()->TMPL->tagdata;
    $new_str = "<strong>". $ee_str . "</strong>";
    
    $this->return_data = $new_str;
}
fixed code
Source Link
Romans-8---31-39
  • 2.9k
  • 1
  • 15
  • 20

Try using the php function addslashes:

<?php
$str = "Is your name O'reilly?";

// Outputs: Is your name O\'reilly?
echo addslashes($str);
?>

So for EE you could have something like:

<p>This is the title and excerpt of this entry: "
    <?php 
        $str = "<strong>addslashes"<strong>". addslashes({title})< . "</strong> : ";
        $str .= "addslashesaddslashes({post_excerpt})";; // combine title and post_excerpt
        echo  stripslashes($str); // remove the slashes.
    ?>
"</p>

Try using the php function addslashes:

<?php
$str = "Is your name O'reilly?";

// Outputs: Is your name O\'reilly?
echo addslashes($str);
?>

So for EE you could have something like:

<p>This is the title and excerpt of this entry: "
    <?php 
        $str = "<strong>addslashes({title})</strong> : ";
        $str .= "addslashes({post_excerpt})"; // combine title and post_excerpt
        echo  stripslashes($str); // remove the slashes.
    ?>
"</p>

Try using the php function addslashes:

<?php
$str = "Is your name O'reilly?";

// Outputs: Is your name O\'reilly?
echo addslashes($str);
?>

So for EE you could have something like:

<p>This is the title and excerpt of this entry: "
    <?php 
        $str = "<strong>". addslashes({title}) . "</strong> : ";
        $str .= addslashes({post_excerpt}); // combine title and post_excerpt
        echo  stripslashes($str); // remove the slashes.
    ?>
"</p>
Source Link
Romans-8---31-39
  • 2.9k
  • 1
  • 15
  • 20

Try using the php function addslashes:

<?php
$str = "Is your name O'reilly?";

// Outputs: Is your name O\'reilly?
echo addslashes($str);
?>

So for EE you could have something like:

<p>This is the title and excerpt of this entry: "
    <?php 
        $str = "<strong>addslashes({title})</strong> : ";
        $str .= "addslashes({post_excerpt})"; // combine title and post_excerpt
        echo  stripslashes($str); // remove the slashes.
    ?>
"</p>