1

I know there must be a better way of writing this i just can not find it or am not asking the right question.

How would i wright multiple str_replace in one statement?

Here is my code

function create() {
if(array_key_exists('createFolder',$_POST)){
  $data = array(
    'folderName' => $this->input->post('folderName')
 // 'time' => date('Y-m-d H:i:s',now())
  );
  $data = str_replace(' ', '_', $data);
  $data = str_replace('.', '_', $data);
  $data = str_replace('?', '_', $data);
  $datestring = "Year: %Y Month: %m Day: %d - %h:%i %a";
  $time = time();
  // $data = str_replace(' ', '_', $data);
  $this->index_model->createFolder($data, $datestring, $time);
}
$this->foldercreated();

}

2 Answers 2

3

you can use an array:

$data = str_replace(array(' ', '.', '?'), '_', $data);
Sign up to request clarification or add additional context in comments.

Comments

2

Use an array like $data = str_replace(array(' ', '.', '?'), '_', $data);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.