Preg_replace () str_replace () apostrophe is a nightmare! - The Drupal menu image is being replaced

Can someone help me decode why this is not working?

$cssid = preg_replace("/'/", "", $cssid);

Trying to strip single quote marks from some html ...

Thanks! N

EDIT This is a complete function - it is designed to restore Drupal menus using images, and it applies CSS classes to each element, allowing you to select the image you want. You need to remove spaces and apostrophes or CSS selector failure.

The name of the menu item causing this whole problem is the following:

What new

Pretty harmless as you think. (Except for this single)

function primary_links_add_icons() {
  $links = menu_primary_links();
  $level_tmp = explode('-', key($links));
  $level = $level_tmp[0];
  $output = "<ul class=\"links-$level\">\n";   
  if ($links) {
    foreach ($links as $link) {
        $link = l($link['title'], $link['href'], $link['attributes'], $link['query'], $link['fragment']);
        $cssid = str_replace(' ', '_', strip_tags($link));
        $cssid = str_replace('\'', '', $cssid);
        /*$link = preg_replace('#(<a.*?>).*?(</a>)#', '$1$2', $link);*/
        $output .= '<li id="'.$cssid.'">' . $link .'</li>';
    };
    $output .= '</ul>';
  }
  return $output;
}

EDIT saga continues ...

I noticed that in PHPMYADMIN the following error occurs:

PHP mbstring , , . mbstring phpMyAdmin - .

, ?

SQL:

('primary-links', 951, 0, 'http://www.google.com', '', 'What' New',

FireBug :

<li id="What's_New">

"What @s New", str_replace() , . , , , . , , , , - PHP .

, - ... , l(), , , ?! ...

function primary_links_add_icons() {
  $links = menu_primary_links();
  $level_tmp = explode('-', key($links));
  $level = $level_tmp[0];
  $output = "<ul class=\"links-$level\">\n";   
  if ($links) {
    foreach ($links as $link) {
        $link['title'] = str_replace('\'', '', $link['title']);
        $link = l($link['title'], $link['href'], $link['attributes'], $link['query'], $link['fragment']);
        $cssid = str_replace(' ', '_', strip_tags($link));      
        /*$link = preg_replace('#(<a.*?>).*?(</a>)#', '$1$2', $link);*/
        $output .= '<li id="'.$cssid.'">' . $link .'</li>';
    };
    $output .= '</ul>';
  }
  return $output;
}

2 ...

, drupal , , , .

+3
5

CSS- - :

: , css . ( )

css-. .

, :

    #primary-tv
{
    display: block;
    width: 90px;
    height: 0px;
    padding-top: 41px;
    background: url(images/nghtv.png);
}

90 x 41px

:

$cssid = preg_replace("&#039;","",htmlspecialchars($cssid, ENT_QUOTES));
+2

.

+2

. str_replace ?

$cssid = str_replace("'", "", $cssid);
+1

str_replace("'","") , , , , ('), () ('`Ė™ ̛̉). (') - ?

Or maybe the value $cssidis replaced with the original by some other error?

Perhaps you are looking at the wrong result for the results?

Or perhaps you accidentally run a different copy of the code than the one you are editing - by the way, this is very annoying when this happens! :)

+1
source

Given that you think this is HTML, it could be represented as & # 39, and not ??

+1
source

Source: https://habr.com/ru/post/1717342/


All Articles