1

hi all,
i need to split a string and place it in two strings..like

$f1=123 4567 is a string.
i need to place 123 in $f2 and 4567 in $f3

how to do that can any one help me

4
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by cwarn23
0

Here is ur code.

<?
	$f1='123 4567';
	$temp = explode(' ',trim($f1));
	$f2 = $temp[0];
	$f3 = $temp[1];
?>
0

Hi Dear,

<?php
$string  = "123 4567";
$result = explode(" ", $string);
echo $var_1=$result[0]; 
echo $var_2=$result[1]; 
?>

Edited by __avd: Added [code] tags.

0

Yes, the same code as i write.

Hi Dear,

<?php
$string = "123 4567";
$result = explode(" ", $string);
echo $var_1=$result[0];
echo $var_2=$result[1];
?>

0

I think what you are after is the str_split(), unset(), and implode() functions. Below is an example of how I would do it.

<?php
function parts($string) {
    $tmp=str_split($string,3);
    $a=$tmp[0];
    unset($tmp[0]);
    $b=implode('',$tmp);
    return array($a,$b);
    }
///////////////////////////////////////
//Do Not Edit Above

$data = parts(1234567890);
echo $data[0];
echo '<br>';
echo $data[1];
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.