Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.