Remove a string from the beginning of a string in PHP

Remove a string from the beginning of a string in PHP

In this post, i will tell you how to remove a string from beginning of a string in PHP.

Sometime you have a prefix in a variable and you need to remove if given string has prefix then these examples will help you to find out if prefix exist in given string then it will remove it from string.

Example 1: Using substr

In this example, i have a number with country code and i want to get only number without country code then first i check if number has country code then remove it from number.

  1. $conuntry_code = '91';
  2. $number = '918888888888';
  3. if (substr($number, 0, strlen($conuntry_code)) == $conuntry_code) {
  4. $number = substr($number, strlen($conuntry_code));
  5. }
  6. echo $number;
Example 1: Using ltrim
  1. $conuntry_code = '91';
  2. $number = '918888888888';
  3. echo ltrim($number,$conuntry_code);

Phone: (+91) 8800417876
Noida, 201301
sakarya escort akyazı escort arifiye escort erenler escort eve gelen escort ferizli escort geyve escort hendek escort otele gelen escort sapanca escort söğütlü escort taraklı escort
escort bayan escort bayan escort bayan escort bayan escort bayan escort bayan escort bayan sakarya escort sakarya escort sakarya escort sakarya escort sakarya escort sakarya escort sakarya escort adapazarı escort adapazarı escort adapazarı escort adapazarı escort adapazarı escort adapazarı escort adapazarı escort serdivan escort serdivan escort serdivan escort serdivan escort serdivan escort serdivan escort serdivan escort sakarya escort bayan sakarya escort bayan sakarya escort bayan sakarya escort bayan sakarya escort bayan sakarya escort bayan sakarya escort bayan escort sakarya escort sakarya escort sakarya escort sakarya escort sakarya escort sakarya escort sakarya serdivan escort sapanca escort karasu escort hendek escort izmir escort