• 0

[PHP] Strings with double quotes to array


Question

Hello, how can I convert a string with double quotes into an array? Is there a function for doing it?

for example

$string = "\"one\", \"two\"";

$array1 = array($string);

if i echo $array1[0] it will display "one", "two" and if I echo $array1[1] it will display nothing, what I want to do is to store the string to $array1 like this, $array1 = array("one","two") so that if I echo $array1[0] it will display one and if I echo $array1[1] it will display two.

How will I do it? Thank you very much, :)

4 answers to this question

Recommended Posts

  • 0

$string = "\"one\", \"two\"";

can be changed to...

$string = '"one", "two"';

then explode() by the comma, so all in all:

$string = '"one", "two"';
$array = explode(", ", $string);

You could keep $string as it was, but my way looks cleaner :) Simple, huh?

Note, that is to keep the quotes intact; if you just wanted the values inside the quotes:

$string = 'one, two';
$array = explode(", ", $string);

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Well to finalise the thread, I bought the addin card as recommended but had teething problems trying to connect it to my eGPU. After much research, I found that rated cabling is a thing and after connecting a rated thunderbolt 4 cable to the new USB addin card I started troubleshooting. A few BIOS tweaks and updates here and there and everything is now connected and working. New eGPU is being picked up by Thunderbolt Control Center Thank you to anyone that stopped and read the thread especially to the tech resources that stopped to post and help. It was of massive help being able to reach out to the community as always. I just hope I haven't wasted too much of the community time trying to diagnose the problem. Thanks for your help again. 😊 Kind regards
    • they keep making "changes" to stuff that isn't broke if I was them I'd just stop making changes to classic and focus on fixing the other mess
    • Every Xbox is a slimmed-down and modified Windows. Xbox 1 (2002) was a Windows NT Xbox 360 Windows 8 Xbox One Windows 10 Xbox SX Windows 11 all with versions with specific services just for games. The Windows that will come on laptops will be a slimmed-down Windows 11 Home focused on games.
    • The problem was that people who have played Extraction Shooters said there were too many missing features. Like Proximity Chat ...because of "toxicity". Lack of any story development even actually outlined. "Too watered down" for regular Extraction Shooter Enjoyers. Stupid amount of Aim Assistance on MnK. Questionable outdoor map design (how can something so "colorful" be so effing dull). Not to mention people still ###### they seemed to use the Marathon name and added in the alien/npcs after the fact, stappled on some other game concept they were working on. Like Arkane Studios was forced to use Prey as a title for their own original IP, by Bethesda to sucker in people for name recognition and ownership over the Prey IP. Which backfired with lower sales, due to the people realizing not a sequel or reboot, and the people who didn't like the original Prey.
  • Recent Achievements

    • Explorer
      Jdoe25 went up a rank
      Explorer
    • First Post
      Ian_ earned a badge
      First Post
    • Explorer
      JaviAl went up a rank
      Explorer
    • Reacting Well
      Cole Multipass earned a badge
      Reacting Well
    • Reacting Well
      JLP earned a badge
      Reacting Well
  • Popular Contributors

    1. 1
      +primortal
      665
    2. 2
      ATLien_0
      283
    3. 3
      Michael Scrip
      224
    4. 4
      +FloatingFatMan
      190
    5. 5
      Steven P.
      146
  • Tell a friend

    Love Neowin? Tell a friend!