简体   繁体   中英

Split strings and store in array

I have a variable called : $elementname

The print values using :

print_r($elementname) is :

hardwareaccessIPsdefaultgwinterface_nameinterface_rxinterface_txinterface_error

While, var_dump($elementname) is :

string(8) "hardware"
string(6) "access"
string(3) "IPs"
string(9) "defaultgw"
string(14) "interface_name"
string(12) "interface_rx"
string(12) "interface_tx"
string(15) "interface_error"

My question is how may i split this strings and store in an array ?

From the print_r, it looks joined with no delimiter :( There must be a way since var_dump was able to split it in the output.

It probably has whitespace character that is not visible to us. try this myarray will have the splitted data like you wanted

$myarray = preg_split("[\s]",$elementname)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM