UCwords သည် စကားလုံး တစ်လုံး၏ပထမစာလုံးကို default မှခွဲထုတ်ထားသည့်စကားလုံး၏ပထမစာလုံးကိုသာဖော်ပြလိမ့်မည်။ ၎င်းသည်တုံးတို (-),
<?php
$title = "my-php_script example";
$formatted = ucwords($title);
echo $formatted; // ထုတ်လုပ်ခြင်း:My-php_script Example
?>
ယခုအချိန်တွင် "PHPP_Script" သည်စာလုံးအသေးဖြင့်နေဆဲဖြစ်ပြီးမှန်ကန်စွာ format လုပ်ထားခြင်းမရှိပါ။
ရှောင်ရှားခြင်းနည်းလမ်း - သင်သည်ခွဲခြမ်းစိတ်ဖြာမှုကိုစိတ်ကြိုက်ပြုပြင်နိုင်သည်သို့မဟုတ်အခြားခွဲခြမ်းစိတ်ဖြာများကိုပထမနေရာများဖြင့်အစားထိုးနိုင်ပြီး,
<?php
function ucwords_custom($string, $delimiters = ['-', '_']) {
foreach ($delimiters as $delimiter) {
$string = str_replace($delimiter, ' ', $string);
}
$string = ucwords($string);
foreach ($delimiters as $delimiter) {
$string = str_replace(' ', $delimiter, $string);
}
return $string;
}
echo ucwords_custom("my-php_script example"); // ထုတ်လုပ်ခြင်း:My-PHP_Script Example
?>
အကယ်. input string သည်တစ်စိတ်တစ်ပိုင်းသို့မဟုတ်အပြည့်အဝစာလုံးများကိုအပြည့်အဝအမြတ်ထုတ်ခံရပါက UCwords များကို တိုက်ရိုက်အသုံးပြုခြင်းသည်ရလဒ်များကိုရှုပ်ထွေးစေနိုင်သည်။
<?php
$title = "tHe quick bROWN foX";
$formatted = ucwords($title);
echo $formatted; // ထုတ်လုပ်ခြင်း:THe Quick BROWN FoX
?>
ဤအချိန်တွင်အချို့သောစကားလုံးများသည်စာလုံးအကြီးနှင့်အသေးနှင့်ရောနှောနေတုန်း, ခေါင်းစဉ်ပုံစံကိုမအောင်မြင်ပါ။
ရှောင်ကြဉ်ပါ ။
<?php
$title = "tHe quick bROWN foX";
$formatted = ucwords(strtolower($title));
echo $formatted; // ထုတ်လုပ်ခြင်း:The Quick Brown Fox
?>
UCwords သည် စာသားအတိုင်းကောင်းစွာအလုပ်လုပ်သည်။
<?php
$title = 'visit <a href="https://gitbox.net/path">our site</a>';
echo ucwords($title);
// ရလဒ်အမှား - ကိုင်တွယ်တံဆိပ်များဖြစ်လိမ့်မည်,ဖြစ်လာ Visit <A Href="Https://Gitbox.Net/Path">Our Site</A>
?>
ရှောင်ကြဉ်ပါ ။ tags များကိုပထမ ဦး ဆုံးဖြည်ချနိုင်, စာသားအစိတ်အပိုင်းများကိုဖြစ်အောင်လုပ်နိုင်သည်, ထို့နောက်သူတို့ကိုပြန်ကြည့်သို့မဟုတ် URL ကိုကာကွယ်ပါ။ လွယ်ကူသောနည်းလမ်းမှာ HTML tags များကိုကျော်ရန်ဖြစ်သည်။
<?php
function ucwords_without_tags($text) {
return preg_replace_callback('/([^<>]+)(?=<|$)/', function($matches) {
return ucwords(strtolower($matches[1]));
}, $text);
}
echo ucwords_without_tags('visit <a href="https://gitbox.net/path">our site</a>');
// ထုတ်လုပ်ခြင်း:Visit <a href="https://gitbox.net/path">Our Site</a>
?>