how to get substring of string without using substr() function in php ????

Answers were Sorted based on User's Feedback



how to get substring of string without using substr() function in php ????..

Answer / abhijit sil

Accessing single characters in a string can be achived
using "curly braces"
<?php

$string = 'abcdef';
echo $string{0}; // a
echo $string{3}; // d
echo $string{strlen($string)-1}; // f

?>

Is This Answer Correct ?    11 Yes 0 No

how to get substring of string without using substr() function in php ????..

Answer / dheeraj

Use explode()just notice the following code. here it splits
a string to parts and forms an array. Now u assign the array
element to a string.

<?php
$str = "Hello world. It's a beautiful day.";
print_r (explode(" ",$str));
?>

Is This Answer Correct ?    5 Yes 1 No

how to get substring of string without using substr() function in php ????..

Answer / nadeem sartawi

Write a PHP function that Returns the part of string
specified by the start and length parameters.

Hint 1: the function accepts three parameters.
Parameter:Description
string :Required. Specifies the string to return a part of
start :Required. Specifies where to start in the string
length :Optional. Specifies the length of the returned
string. :Default is to the end of the string.
Hint 2: YOU ARE NOT ALLOWED TO USE THE "substr" FUNCTION.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More PHP Interview Questions

Actually am working in existing project which is developed in .net, am converting the .net into php code. am facing problem after uploading the .php in server. amgetting the error message like "The page cannot be found" but its working perfectly in local host

2 Answers  


What are the difference between abstract class and interface?

4 Answers  


Do you know what are traits?

0 Answers  


How to get the DNS servers of a domain name?

1 Answers   Life Infotech,


how can i get USA time using php...

1 Answers  


Explain what does $_files means?

0 Answers  


What is meant by ‘passing the variable by value and reference' in php?

0 Answers  


How do I run a php program in dreamweaver?

0 Answers  


How to upload a file (may be a .txt or a .doc file) from a php script/file?

1 Answers  


How can I loop through the members of an array?

1 Answers   Rushmore Consultancy,


What are the different types of PHP arrays?

0 Answers  


coding for deleting items form data base on select

1 Answers  


Categories