1

consider bellow variable x.is there any method to separate this to two parts at the "slash" and assign them to two variable in php. there should be only the slash between two words.

<?php
    $x="hello/welcome";
?>
Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
DScript
  • 285
  • 2
  • 8

2 Answers2

3
<?php
$x="hello/welcome";
$a = explode("/", $x);

// $a[0] = "hello"
// $a[1] = "welcome"

?>

Is that helpful?

TN888
  • 7,659
  • 9
  • 48
  • 84
2

You can use explode and preg_split both .Try this:-

<?php
    $x="hello/welcome";
    $array = explode("/", $x);
    echo "<pre/>";print_r($array);
?>

Or

<?php
    $x="hello/welcome";
    $y = preg_split('^/^',$x);
    print_r($y);
?>

In both condition output is:-

Array
(
    [0] => hello
    [1] => welcome
)
Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98