Jump to content

[SOLVED] str_replace();


Archimedees

Recommended Posts

 

Hi guys,

 

I have a problem, don't most of us here? ;)

I have a string with spaces, I want to replace the spaces with commas and then explode the string and create an array.

How do I go about this? Please assist me.

 

For example the string might look like this.

 

"weird weirdo quiteweird nuts crazy mad verycrazy banana bonkers"
Link to comment
https://forums.phpfreaks.com/topic/72463-solved-str_replace/
Share on other sites

<?php
$data = "weird weirdo quiteweird nuts crazy mad verycrazy banana bonkers";
$data = str_replace(" ", ",", $data);
$NewData = explode(",", $data );
?>

 

OR JUST, explode with a space delimiter

 

<?php
$data = "weird weirdo quiteweird nuts crazy mad verycrazy banana bonkers";
$NewData= explode(" ", $data );
?>

Link to comment
https://forums.phpfreaks.com/topic/72463-solved-str_replace/#findComment-365383
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.