Hello, I’m trying to find a function in PHP manual that allow me to replace each element of the string with quotations around it.
For example, the code is

$strkeywords = join(', ', $_POST['keywords_main']);
echo $ $strkeywords;

The result of echo is

keyword1, keyword2

I need it to look like (with quotations around each element)

‘keyword1’, ‘keyword2’

Could you please tell me how to achieve needed result?

Thank you,

    Wouldn't just a period work??

    keyword1 = "'" . keyword1;
    keyword1=keyword1 . "'";
    echo keyword 1 should output 'keyword1'

      Your post's title suggests that you are trying to work with an array, but the join() function creates a string as it's an alias of implode().

      Just trying to make sure you are getting the desired results. Are you trying to create an array or string?

        My goal is to create a string, where each word is surrounded by quotations. I need later to input it to an sql statement, such as "SELECT * from tbl WHERE name is IN ('keyword1', 'keyword2')". I tried to input keywords without quoations, it gives an error.

        So, I get from $_POST[keywords_main] multiple keywords, and after I join them, I get a string of keywords without quotations.
        I was thinking about adding quotations to each word in a resulting string $strkeywords , or put keywords in array and add quotations to each array element. I don't know if there is a function either for an array or a string.

        Please help,

        Thank you,

          <?php
          $strkeywords = "'" . join("', '", $_POST['keywords_main']) . "'";
          echo $ $strkeywords;
          ?>

            Thank you!

            Solution ($strkeywords = "'" . join("', '", $_POST['keywords_main']) . "'"😉 is great!

              Write a Reply...