masih arastooyi
masih arastooyi

Reputation: 545

Split a hyphenated string

i want get part of value from a database
i know i must use split code but its going to remove from php
so i must use what now
for example i have

<html>
<header>
<body>
<?php
$value = "10-20-30-40-50-87";
//i want to get 30 for example
?>

i know i can use

$aryStr = split("#", $string); 
 print "$aryStr[0]<br>";
 print "$aryStr[1]";   

but its give me a error in php5.3
so what i must use now for get 40 from value

Upvotes: -3

Views: 1783

Answers (1)

jamis0n
jamis0n

Reputation: 3810

Use PHP explode function to split the $value into an array of Strings.

$value = "10-20-30-40-50-87";
$pieces = explode("-", $value);
echo $pieces[0]; // 10
echo $pieces[1]; // 20

Upvotes: 1

Related Questions