$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>php - str_replace remove words from title|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

php - str_replace remove words from title

matteradmin10PV0评论

I have a site that reviews movies (DVD/Blu-ray, etc.)So every review in a particular category will have (Blu-ray) after the title, another will have DVD and so forth. i.e. Avengers: Infinity War (Blu-ray). I want to trim the format of the disc (Blu-ray) from the page title and I have this code, but it's not working. Wasn't sure what the issue was.

<span style="color: #ffffff">About <?php if (in_category('5447') ):?>
<?php
echo str_replace("(Blu-ray)","&nbsp;","<?php the_title(); ?>");
?>
</span>
<?php endif; ?>

So, in essence, I can grab the title and it will read: Avengers: Infinity War (Blu-ray)

but I want it to read: Avengers: Infinity War

I have a site that reviews movies (DVD/Blu-ray, etc.)So every review in a particular category will have (Blu-ray) after the title, another will have DVD and so forth. i.e. Avengers: Infinity War (Blu-ray). I want to trim the format of the disc (Blu-ray) from the page title and I have this code, but it's not working. Wasn't sure what the issue was.

<span style="color: #ffffff">About <?php if (in_category('5447') ):?>
<?php
echo str_replace("(Blu-ray)","&nbsp;","<?php the_title(); ?>");
?>
</span>
<?php endif; ?>

So, in essence, I can grab the title and it will read: Avengers: Infinity War (Blu-ray)

but I want it to read: Avengers: Infinity War

Share Improve this question asked Apr 12, 2020 at 16:05 user34872user34872 153 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 0

the_title() will directly output the title - for your purpose in a string manipulation, you need to use get_the_title() https://developer.wordpress/reference/functions/get_the_title/

you also have some php syntax error;

try to use:

<?php
echo str_replace( "(Blu-ray)","&nbsp;", get_the_title() );
?>

you have mistake hire :

echo str_replace("(Blu-ray)","&nbsp;","<?php the_title(); ?>");

should be : echo str_replace( "(Blu-ray)", "", get_the_title() );

1 - the_title() echo directly the title, you cannot do enything whit the title.

2- when call the str_replace() dot put inside php tags ;)

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far