Current location: Hot Scripts Forums » Programming Languages » PHP » Arrays


Arrays

Reply
  #1 (permalink)  
Old 10-24-04, 03:28 PM
cebuy cebuy is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Arrays

I have a mysql database set up for affiliate links that contain ' and " in them. I am trying to rotate these links and I am trying to learn arrays for the first time. In an array I notice that " is used a lot. Do I need to use \" to escape it? I have the magic quotes thing turned on at my my server but I was wondering if anyone had any pointers on how to approach this. Many of the these affiliate links are several lines of html code and I also will be using this code to rotate text and sentences for search engine optmization of doorway pages...
Any thoughts???

Chris
Reply With Quote
  #2 (permalink)  
Old 10-25-04, 07:40 AM
moronovich moronovich is offline
Junior Code Guru
 
Join Date: Oct 2004
Posts: 460
Thanks: 0
Thanked 0 Times in 0 Posts
again, this is the similar question with, "how to distinguish single quote (') and double quote (") in a string?" i'll try to give a brief explanation on it.
1. single quotes (') are used to enclose string which won't be parsed by php.
eg:
PHP Code:

   $myString 'This is unparsed';

   print 
'Is this unparsed? $myString'//would print Is this unparsed? $myString 
2. double quotes (") are used to enclose string which will be parsed by php.
eg:
PHP Code:

   $myString "This is parsed";

   print 
"Is this unparsed? $myString"//would print Is this unparsed? This is parsed 
When to use single quotes:
#if the string doesn't contain php vars
#if you care about micro/milliseconds spent in parsing a string
When to use double quotes:
#if the string contains php vars
#if you don't care about micro/milliseconds spent in parsing a string

Quotes in an array
PHP Code:

$myArray['first'] = 1;

//equivalent with
$myArray = array('first' => 1);

$key 'first';
$myArray[$key] = 1;
//equivalent with
$myArray["$key"] = 1;
//and
$myArray = array("$key=> 1);
//and
$myArray = array('first' => 1); 
When to use backslash (\) in a string / array:
if you want to escape special character or there is a quote in a parsed string.

Good luck with your project..
__________________
just an ignorant noob with moronic solution...

Last edited by moronovich; 10-25-04 at 07:48 AM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
arrays jasperma PHP 3 07-24-04 01:49 PM
Going Insane Over Lists and Arrays mtorbin Perl 3 06-03-04 04:19 AM
Database queries or arrays ? danux PHP 2 03-11-04 07:57 AM
Easy question about arrays... tempa PHP 4 03-09-04 06:13 AM
Javascript vs PHP, problem with arrays Chuff JavaScript 0 10-03-03 04:01 AM


All times are GMT -5. The time now is 04:40 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.