လက်ရှိတည်နေရာ: ပင်မစာမျက်နှာ> နောက်ဆုံးရဆောင်းပါးများစာရင်း> PHP ECHO ထုတ်ပြန်ချက်များတွင် variable များကို hyperlink address များအဖြစ်ပြောင်းလဲခြင်းနည်း Variables add add လုပ်နည်း။

PHP ECHO ထုတ်ပြန်ချက်များတွင် variable များကို hyperlink address များအဖြစ်ပြောင်းလဲခြင်းနည်း Variables add add လုပ်နည်း။

gitbox 2025-06-17

PHP ECHO ထုတ်ပြန်ချက်များတွင် variable များကို hyperlink address များအဖြစ်ပြောင်းလဲခြင်းနည်း Variables add add လုပ်နည်း။

0 က်ဘ်ဆိုက်မဖွံ့ဖြိုးတိုးတက်မှုတွင်မတူညီသောစာမျက်နှာများနှင့်ချိတ်ဆက်ရန် hyperlinks များကိုမကြာခဏအသုံးပြုရန်လိုအပ်သည်။ PHP တွင် Hyperlink များကိုထုတ်လုပ်ရန် HTML code ကို outpl code ကို output လုပ်ထားသည့်အတွက် ECHO ထုတ်ပြန်ချက်များကိုအသုံးပြုနိုင်သည်။ ဒါကြောင့် PHP variable တွေကို echo ကြေညာချက်ထဲမှာ Href link address လို့ဘယ်လိုအသုံးချမလဲ။ ဤဆောင်းပါးသည်ဘုံအကောင်အထည်ဖော်မှုနည်းလမ်းများစွာကိုမိတ်ဆက်ပေးလိမ့်မည်။

1 ။ string concatenator ကိုသုံးပါ "။ "

string ကို concatenator "။ " အားလုံး strings ကို concatenate condatenate နိုင်ပါတယ်။ ၎င်းကို splice php variable များကို splice phip variable များကိုမှန်ကန်သော hyperlink သို့သုံးနိုင်သည်။ ဥပမာအားဖြင့်:

 
$url = "https://www.example.com/user.php?id=";
$id = 123;
echo "<a href='" . $url . $id . "'> အသုံးပြုသူပရိုဖိုင် </a>";

အထက်ပါကုဒ်များတွင် string concatenator မှတဆင့် static html link ကို static HTML link ကို splible variable များကို flict လုပ်ပါသည်။ " ပြီးပြည့်စုံသော hyperlink ထုတ်လုပ်ရန်။

2 ။ နှစ်ဆကိုးကား strings အတွက် embed variable တွေကို embed

PHP သည် variable များကိုနှစ်ဆကိုးကားထားသော strings များဖြင့်တိုက်ရိုက်ထည့်သွင်းရန်, variable ၏တန်ဖိုးကို string ထဲသို့အလိုအလျောက်အစားထိုးရန်ခွင့်ပြုရန်ခွင့်ပြုသည်။ ထို့ကြောင့် PHP variable များကို hyperlinked string ထဲသို့တိုက်ရိုက်ထည့်သွင်းနိုင်သည်။ ဥပမာအားဖြင့်:

 
$url = "https://www.example.com/user.php?id=";
$id = 123;
echo "<a href=\"{$url}{$id}\"> အသုံးပြုသူပရိုဖိုင် </a>";

ဤဥပမာတွင် PHP သည်ဒေါ်လာ URL နှင့် $ ID ၏တန်ဖိုးများကိုအလိုအလျောက်ထည့်သွင်းထားပြီး,

3 ။ Printf function ကိုသုံးပါ

သတ်မှတ်ထားသော format string ကိုအရ PrintF function ကို format လုပ်နိုင်သည်။ format string တစ်ခုအရ "% s" နှင့် "% s" ကဲ့သို့သော "% s" နှင့် "% d" ကဲ့သို့သော formatting သင်္ကေတများကိုသုံးနိုင်သည်။ output hyperlinks သို့ Printf ကိုလည်းသုံးနိုင်သည်။ ဥပမာအားဖြင့်:

 
$url = "https://www.example.com/user.php?id=";
$id = 123;
printf("<a href='%s%d'> အသုံးပြုသူပရိုဖိုင် </a>", $url, $id);

ဤကုဒ်တွင်% s သည် output string ကိုကိုယ်စားပြုသည်။ % d သည် output output ကိုကိုယ်စားပြုသည်။

မှတ်သားရန်အရာ

Hyperlinks မှ echo ထုတ်ပြန်ချက်များကိုအသုံးပြုသောအခါအောက်ပါအချက်များကိုအာရုံစိုက်ရန်လိုအပ်သည် -

  • Hyperlink address သည်မှန်ကန်သော protocol ကိုအသုံးပြုနေကြောင်းသေချာစေရန် (HTTP သို့မဟုတ် https) သို့မဟုတ်၎င်းကိုလက်လှမ်းမမီနိုင်ပါ။
  • output html code သည် standard syntax ကိုလိုက်နာသင့်သည်။
  • Hyperlink text သည်စာဖတ်နိုင်ပြီးအသုံးပြုသူများသည် link ၏ရည်ရွယ်ချက်ကိုနားလည်ရန်ကူညီသည်။

တိုတိုအတွက် string concatenator ကဲ့သို့သောနည်းလမ်းများကို အသုံးပြု. "နှစ်ဆကိုးကား strings embed variable တွေကို embed variable တွေကို embed variable တွေကို embed variable functions ကိုအလွယ်တကူပေါင်းစပ်နိုင်ပါတယ်။ Hyperlinks များကိုထုတ်ယူသောအခါ developer များက link address ၏တိကျမှန်ကန်မှု, HTML syntax ၏စံသတ်မှတ်ချက်နှင့် link textibility ၏ readability ကိုလည်းသေချာစေသင့်သည်။