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 ?    10 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

Explain about Type Juggling in PHP?

2 Answers  


Create a PHP web script with the following attributes: on start, three HTML form elements are shown: an string input field, a checkbox field, a dropdown/pull down list with 5 elements and a submit button. On submission, the form should be redisplayed (while remaining all options/inputs as the user has selected/entered them). Additionally, the selections/inputs of the user should be displayed in text. Please solve this without the use of any external libraries.

1 Answers   Wipro,


which is the best institute for php training near delhi & NCR......& what is the fee for the same....

2 Answers  


How can I know that a variable is a number or not using a JavaScript?

2 Answers  


How do you get the Browser information?

3 Answers   Life Infotech,






What's the diff. between include() and Include_once().

5 Answers   Intrack,


How to use the COM components in PHP?

2 Answers   HCL,


what do you mean by webserver's document root?

3 Answers  


what are Implode and Explode functions?

8 Answers   HCL,


how to make website package setup like desktop software setup ... that front end and backend can include in setup like single package...?

0 Answers  


how can refresh current page automatically, without press any button and anchor tag.

5 Answers  


Extract url from this string? It should be flexible for all strings, not for this string only. "yahoo.comyahoo.co.inhotmail.org"

1 Answers   A1 Technology,






Categories