Jump to content


Photo

explode function question


  • Please log in to reply
2 replies to this topic

#1 netfrugal

netfrugal
  • Members
  • PipPip
  • Member
  • 26 posts

Posted 23 October 2006 - 05:51 PM

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?

#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 23 October 2006 - 06:03 PM

Because of the nature of the beast, you need to escape the backslash, and actually use two:
<?php
$separated = explode("\\", $word);
?>

You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 23 October 2006 - 06:03 PM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users