php ltrim not grabbing beginning dash
looking for a solution to my problem. searching this place and google for an answer but 开发者_StackOverflow中文版can't gain much ground.
basically I want to remove "Issue 119 - " from a title.
so far I got the "Issue 119" to be removed but the " - " is persistent sadly can anyone help me. would love it if I could amend the $cut variable line
$grissueno is from the custom field in my wordpress post = 119 string.
the_title presents the string "Issue 119 - Editorial: Troubled on every side" (example title)
<?php
$cut = "Issue " . $grissueno; //joining the word issue and dynamic number together
$title = the_title('','',false ); //telling wordpress to let php use the title string
$trim = str_replace($cut, "", $title); //cutting out the Issue 119
echo ltrim($trim, " - "); //trying to remove the dash but failing
?>
thanks for any help
ltrim only takes two arguments. the string to trim, and a list of characters that are trimmable:
$trim = ltrim($title, "- ");
is what you want. Yours is trimming an empty string (""
).
Change $cut = "Issue " . $grissueno;
to $cut = "Issue " . $grissueno . " - ";
and forget about ltrim()
.
Try this:
$title = "Issue 119 - Editorial: Troubled on every side";
echo preg_replace('/Issue \d+ - (.*)/', '$1', $title);
Try replacing the whole lot with: (EDITED)
echo ltrim(str_replace("Issue $grissueno",'',the_title('','',FALSE)),"- \t\n\r\0\x0B");
精彩评论