Jump to content

Archived

This topic is now archived and is closed to further replies.

netfrugal

explode function question

Recommended Posts

I am trying to separate this:  mydomain\myname


To do this I am using the explode function as such:

$word = "mydomain\myname";
$separated = explode("\", $word);

echo $separated[0];
echo $separated[1];

However, the backslash does not work.  Is there a way to explode backslashes?

Share this post


Link to post
Share on other sites
Because of the nature of the beast, you need to escape the backslash, and actually use two:
[code]
<?php
$separated = explode("\\", $word);
?>
[/code]

Share this post


Link to post
Share on other sites
Use two backslashes instead:
$separated = explode("\\", $word);

if you use one backslash on its own PHP will think you;re escaping the closing double quote. Use two backslashes together (\\) prevents this.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.