paulmagm Posted November 3, 2021 Share Posted November 3, 2021 'title' => "{$page['content_slug']} ({$page['content_title']}) ", Can someone help me how to insert the ucfirst in this line? Thank you for your help. Quote Link to comment https://forums.phpfreaks.com/topic/314159-use-ucfirst-in-a-title/ Share on other sites More sharing options...
jarvis Posted November 3, 2021 Share Posted November 3, 2021 Is it not possible to do something like: $content_slug = ucfirst($page['content_slug']); $content_title = ucfirst($page['content_title']); 'title' => "{$content_slug} ({$content_title})", Maybe a better option but I'd convert them first, then insert them. Quote Link to comment https://forums.phpfreaks.com/topic/314159-use-ucfirst-in-a-title/#findComment-1591688 Share on other sites More sharing options...
paulmagm Posted November 3, 2021 Author Share Posted November 3, 2021 Thanks make sense. But crashed my site. But why? This is the hole context then. $data = [ $content_slug = ucfirst($page['content_slug']); $content_title = ucfirst($page['content_title']); 'title' => "{$content_slug} ({$content_title}) ", 'meta.description' => $description, 'page' => $page, ]; return $app->render($template, $data); } Quote Link to comment https://forums.phpfreaks.com/topic/314159-use-ucfirst-in-a-title/#findComment-1591689 Share on other sites More sharing options...
jarvis Posted November 3, 2021 Share Posted November 3, 2021 Because of the semi-colon at the end of each declaration and those being declared inside $data. You would need to move them outside like so: $content_slug = ucfirst($page['content_slug']); $content_title = ucfirst($page['content_title']); $data = [ 'title' => "{$content_slug} ({$content_title}) ", 'meta.description' => $description, 'page' => $page, ]; return $app->render($template, $data); } Quote Link to comment https://forums.phpfreaks.com/topic/314159-use-ucfirst-in-a-title/#findComment-1591690 Share on other sites More sharing options...
Phi11W Posted November 3, 2021 Share Posted November 3, 2021 How about something like this? 'title' => sprintf( '%s %s', ucfirst( $page['content_slug'] ), ucfirst( $page['content_title'] ) ), Regards, Phill W. Quote Link to comment https://forums.phpfreaks.com/topic/314159-use-ucfirst-in-a-title/#findComment-1591691 Share on other sites More sharing options...
paulmagm Posted November 3, 2021 Author Share Posted November 3, 2021 32 minutes ago, jarvis said: Because of the semi-colon at the end of each declaration and those being declared inside $data. You would need to move them outside like so: $content_slug = ucfirst($page['content_slug']); $content_title = ucfirst($page['content_title']); $data = [ 'title' => "{$content_slug} ({$content_title}) ", 'meta.description' => $description, 'page' => $page, ]; return $app->render($template, $data); } That works now. Thank you very much! Quote Link to comment https://forums.phpfreaks.com/topic/314159-use-ucfirst-in-a-title/#findComment-1591692 Share on other sites More sharing options...
ginerjm Posted November 3, 2021 Share Posted November 3, 2021 'title' => ucfirst($page['content_slug']) . ' ' . ucfirst($page['content_title']), Quote Link to comment https://forums.phpfreaks.com/topic/314159-use-ucfirst-in-a-title/#findComment-1591697 Share on other sites More sharing options...
paulmagm Posted November 3, 2021 Author Share Posted November 3, 2021 And here? breadcrumb_add('page', $page['content_slug']); i have to learn more php. too much ' for a frontend developer. Quote Link to comment https://forums.phpfreaks.com/topic/314159-use-ucfirst-in-a-title/#findComment-1591735 Share on other sites More sharing options...
ginerjm Posted November 3, 2021 Share Posted November 3, 2021 Huh? Quote Link to comment https://forums.phpfreaks.com/topic/314159-use-ucfirst-in-a-title/#findComment-1591738 Share on other sites More sharing options...
paulmagm Posted November 3, 2021 Author Share Posted November 3, 2021 2 hours ago, paulmagm said: And here? breadcrumb_add('page', $page['content_slug']); i have to learn more php. too much ' for a frontend developer. I'm not able to add ucfirst in this line without crashing the hole website. Quote Link to comment https://forums.phpfreaks.com/topic/314159-use-ucfirst-in-a-title/#findComment-1591739 Share on other sites More sharing options...
ginerjm Posted November 4, 2021 Share Posted November 4, 2021 What exactly does 'crashing' mean to you/us? Are you getting an error message? Do you have error reporting enabled? You are calling a function with two arguments. What does the function do? It doesn't appear to return anything so why do you not use the ucfirst function on the 2 args before you use them in the function calll? That is what I would do. Or I would use the function on each of the args in the call. Show us this code that is 'crashing' your hole(?) website. Quote Link to comment https://forums.phpfreaks.com/topic/314159-use-ucfirst-in-a-title/#findComment-1591740 Share on other sites More sharing options...
ginerjm Posted November 4, 2021 Share Posted November 4, 2021 breadcrumb_add('Page', ucfirst($page['content_slug'])); The first argument I simply made a change to. The second arg I added the function to the var you were passing into the function. Pretty simple, huh? Of course I am assuming that your var is actually a string. Correct? Quote Link to comment https://forums.phpfreaks.com/topic/314159-use-ucfirst-in-a-title/#findComment-1591741 Share on other sites More sharing options...
paulmagm Posted November 4, 2021 Author Share Posted November 4, 2021 8 hours ago, ginerjm said: breadcrumb_add('Page', ucfirst($page['content_slug'])); The first argument I simply made a change to. The second arg I added the function to the var you were passing into the function. Pretty simple, huh? Of course I am assuming that your var is actually a string. Correct? Now it works. Thank you very much! Quote Link to comment https://forums.phpfreaks.com/topic/314159-use-ucfirst-in-a-title/#findComment-1591743 Share on other sites More sharing options...
ginerjm Posted November 4, 2021 Share Posted November 4, 2021 Did you learn anything from what I did? Quote Link to comment https://forums.phpfreaks.com/topic/314159-use-ucfirst-in-a-title/#findComment-1591748 Share on other sites More sharing options...
paulmagm Posted November 5, 2021 Author Share Posted November 5, 2021 yes, thanks! Quote Link to comment https://forums.phpfreaks.com/topic/314159-use-ucfirst-in-a-title/#findComment-1591777 Share on other sites More sharing options...
ginerjm Posted November 5, 2021 Share Posted November 5, 2021 HTH Quote Link to comment https://forums.phpfreaks.com/topic/314159-use-ucfirst-in-a-title/#findComment-1591782 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.