John Davidson

php - removing certain elements from a string

0 comments
Message:


I would like to change the following content to a string in php so that the names come out as this


itai,bliss

instead of this which is showing in my blade file


"["itai","bliss"]"

ive tried to do this in my controller but its showing an invalid result.


$minute = Minutes::find($id);
$minuteSlash = $minute->attendances;
$attendees = substr($minuteSlash, 2, -2);

is there a way i can do this



My Answer:
You can achieve this by using the `str_replace` function in PHP. Here's an example code snippet to remove certain elements from a string:

php
// Original string
$string = "this_itai,this_bliss,this_john";

// Elements to remove
$elementsToRemove = array("this_", ",this_");

// Replace elements with an empty string
$newString = str_replace($elementsToRemove, "", $string);

// Output the new string
echo $newString;
?>


In this example, we first define the original string and an array of elements to remove. We then use the `str_replace` function to replace these elements with an empty string, effectively removing them from the original string. Finally, we output the new string which should now contain the desired names separated by commas.

Rate this post

3 of 5 based on 3222 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us