How To Remove Quote In String And Convert To Array In PHP

admin_img Posted By Bajarangi soft , Posted On 19-01-2021

In PHP we can convert string into array using expload function.So today we discuss how to do to it .

How To Remove Quote In String And Convert To Array In PHP

Lets Start,
Step 1:Create index.php file and create array as below.

<?php
$data="#1231324,#12345,#76827,#14749";
?>

Step 2:Now use exploade function to Separate string and encode and decode it with json function.
<?php
$data="#1231324,#12345,#76827,#14749";
$array=json_encode(explode(',', $data));

$arr = json_decode($array);
?>


Step 3:Now display array using foreach loop
<?php
$data="#1231324,#12345,#76827,#14749";
$array=json_encode(explode(',', $data));


$arr = json_decode($array);
foreach($arr as $imgpos => $value){

    echo "<h1>".$value."</h1>"."<br>";
}
?>


Complete Code For Removing Quote In String And Convert To Array In PHP.
<!doctype html>
<html lang="en">
<head>
    <title>How To Remove Quote In String And Convert To Array In PHP</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
          integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

    <link rel="stylesheet" href="index.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
</head>
<body>
<div class="container">
    <div class="text-center">
        <br><br><br><br>
        <h4>
            How To Remove Quote In String And Convert To Array In PHP
        </h4>
    </div>
</div>
<main  class="py-4" style="margin-top: 20px">
    <div class="flex-center position-ref full-height">
        <div class="container">
                <?php
                $data="#1231324,#12345,#76827,#14749";
                $array=json_encode(explode(',', $data));


                $arr = json_decode($array);
                foreach($arr as $imgpos => $value){

                    echo "<h1>".$value."</h1>"."<br>";
                }
                ?>

        </div>
    </div>
</main>
</body>
</html>

Related Post