Web студия "GrandView"
  Главная   Написать Контакты
   
   
О проекте
Руководство php
 

Variable substitution in strings

PHP 4 adds a new mechanism to variable substitution in strings. You can now finally access object member variables and elements from multidimensional arrays within strings.

To do so you have to enclose your variables with curly braces with the dollar sign immediately following the opening brace: {$...}

To embed the value of an object member variable into a string you simply write "text {$obj->member} text" while in PHP 3 you had to use something like "text ".$obj->member." text".

This should lead to more readable code, while it may break existing scripts written for PHP 3. But you can easily check for this kind of problem by checking for the character combination {$ in your code and by replacing it with \{$ with your favorite search-and-replace tool.



add a note add a note User Contributed Notes
Variable substitution in strings
K.Tomono
15-Apr-2003 06:54
>But you can easily check for this kind of problem by
> checking for the character combination {$ in your code
> and by replacing it with \{$ with your favorite
> search-and-replace tool.

A code which was written below may exist.

  if("aaa"){$foo="bar";}

I've done like the following for the `easy checking`.  (on Linux - tcsh)

  egrep '".*\{\$.+\}.*"' *.php

also using Regexp Search of a Windows Editor (Emacs compatible.)

Search Word  : ".*{\$.+}.*"

I'm not so good at treating Regexp. so there may be a lack of
code pattern.

Cookies> <PHP 3 extension
Last updated: Sat, 27 Jan 2007
 
 
Новости
11 июля 2007
Сайт запущен
© 2007 info@grandviewstudio.com

Deprecated: Function set_magic_quotes_runtime() is deprecated in /home/sites/grandviewstudiocom/www/65f67d67a94ad980786580ae69e11c07/sape.php on line 324

Deprecated: Function set_magic_quotes_runtime() is deprecated in /home/sites/grandviewstudiocom/www/65f67d67a94ad980786580ae69e11c07/sape.php on line 330
Z058440144362 Z348613067571