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

Hi all, I have a problem in Apache on windows xp.I tried to unistall apache and install it again. But when in did the installation again, and tried to run apache, i get the following error message, Socketaddresse can just be used once. Make_sock: could not build to address 0.0.0.0.80 No listening sockets available.Shutting down Unable to open logs. and i also get (error) OS2. The system cannot fine the installed service named "Apache2". Please i need some one to help me out with this.I'm really fustrated cuz i need this stuff working as fast as possible. PLEASE HELP ME

2 Answers  


how we can upload and view video files

2 Answers  


what is Opern source?

3 Answers  


i am a php programmer can i be a java programmer?

3 Answers  


How do you run a php script from the command line?

1 Answers  






How can we increase the execution time of a PHP script?

12 Answers   Photon, CyberBeoz, XTX,


if i give Limit for mysql query through php command line script like this for ex. $limit=500; $total_items = 1500; for($start=0;$start<$total_items;){ $command = "/usr/bin/php -q /home/sitename/public_html/admin/feedmanager/test.php feedid ".$_GET['feedid']." start ".$start." end ".$limit ; $start = $start+$limit; $command_result = system($command); } so it's execute command for 3 times so it give limit to sql query but if i have 27000 data so it takes long time? so my question is that is that any way from php command line script that i can use for collect all the data at once?

0 Answers  


how will i set pagination ?

2 Answers  


How can I check if a value is already in an array?

3 Answers   Rushmore Consultancy,


What is meant by nl2br()?

4 Answers   Rushmore Consultancy,


Why we are using PHP than others for web developing?

4 Answers  


Without using forms and hidden variables, how to send variables from a PHP script to another URL using POST method?

2 Answers  






Categories