Menu
PHP BABA LOGO
  • Home
  • Interview Questions
    • PHP String Interview Question
    • PHP Array Interview Qutions
    • jQuery Interview Quetions
    • PHP Interviwe Question on php.ini file
    • htaccess File Interview Quetions
  • About
PHP BABA LOGO

PHP String Interview Question

Posted on May 9, 2017May 18, 2022

Question : Find number in a string?

preg_replace(“/[^0-9]/”,””,$string); Return string
filter_var($str, FILTER_SANITIZE_NUMBER_INT);
preg_match_all(‘!\d+!’, $str, $matches); Return an array

strpos() : Find the postion in string
Example : echo strpos(“I love php, I love php too!”,”php”);
Output: 7

strpos() : Finds the position of the first occurrence of a string inside another string (case-sensitive)

stripos() : Finds the position of the first occurrence of a string inside another string (case-insensitive)

strripos() : Finds the position of the last occurrence of a string inside another string (case-insensitive)\

substr : Return “world” from the string
Example : echo substr(“Hello world”,-1);
Output : d

strrev() : Reverse the string

strrev(“Hello World!”) : !dlroW olleH

 

Question: Output of code :

$str1 = 'yabadabadoo';
$str2 = 'yaba';
echo  $haspostion = strpos($str1,$str2)) {     ;

Output : 0

Explanation : it show 1st occurence of “yaba” in string which is on position 0 show output will be 0. To awoid this problem we have to check it with

if(strpos($str1, $str2) !== false){

//….you code is here

}

Categories

  • Docker
  • Git
  • Interview Questions
  • Laravel
  • Linux
  • php
  • Salesforce

Recent Posts

  • How to check Salesforce current release version
  • Salesforce Certification Coupons / Vouchers
  • Nested / Cascade query in SOQL
  • Declarative tools in salesforce
  • SalesForce Questions

Recent Posts

  • How to check Salesforce current release version January 12, 2023
  • Salesforce Certification Coupons / Vouchers July 19, 2022
  • Nested / Cascade query in SOQL May 11, 2022
  • Declarative tools in salesforce September 24, 2021
  • SalesForce Questions September 24, 2021
©2023 The Tech Paper | Powered by Abhinav Trivedi