0

I have this code here which is meant to display the title tag in quotes besides the code.

$item_output .= '<a'. " title=" . " $item->attr_title " . $attributes .'>';

Can someone please guide on how to get the title in quotes. Currently it is displayed as follows:

<a title=the tag href="http://url.com">

However, it should display as follows:

<a title="the tag" href="http://url.com">

Please help.

I have tried to remove the Quotes as in tried the following but it doesn't work.

$item_output .= '<a'. " title=" . " '$item->attr_title '" . $attributes .'>';

$item_output .= '<a'. " title=" . "' . esc_attr( $item->attr_title ) . '" . $attributes .'>';

$item_output .= '<a'. " title=" . " . esc_attr( $item->attr_title ) . " . $attributes .'>';
Aioros
  • 4,373
  • 1
  • 18
  • 21
Keyur Amin
  • 45
  • 1
  • 1
  • 8
  • See https://stackoverflow.com/questions/7999148/escaping-quotation-marks-in-php as an option for outputting quotes inside of a quoted string. – WOUNDEDStevenJones Jan 11 '19 at 00:54

3 Answers3

0

You are not actually including quotes in the strings you are outputting. An easy way in this case would be:

$item_output .= '<a title="' . $item->attr_title . '" ' . $attributes .'>';
Aioros
  • 4,373
  • 1
  • 18
  • 21
0

This should work (escaping the quotes):

$item_output .= '<a title=\"'. $item->attr_title.'\" '.$attributes.'>';
Johannes
  • 64,305
  • 18
  • 73
  • 130
0

I think you're looking for something like this

$item_output .= '<a title="' . $item->attr_title . '" ' . $attributes .'>';

Output:

<a title="The Title" href="http://url.com">

PHP Fiddle Demo hit "Run" to get the code executed

Mi-Creativity
  • 9,554
  • 10
  • 38
  • 47