За последние 24 часа нас посетили 72604 программиста и 1650 роботов. Сейчас ищут 854 программиста ...

Вывести переменную. Help!

Тема в разделе "Прочее", создана пользователем QQQ, 10 ноя 2008.

  1. QQQ

    QQQ Активный пользователь

    С нами с:
    21 ноя 2007
    Сообщения:
    538
    Симпатии:
    0
    Допустим у меня есть переменная $var. Я делаю так: $var = 'Привет!'; И есть у меня html страничка. <html><body></body></html>. Я делаю так: <html><body><?php $var = 'Привет!'; ?></body></html> Как мне вывести содержимое $var, чтобы было <html><body>Привет!</body></html>?
     
  2. Mete0

    Mete0 Активный пользователь

    С нами с:
    18 дек 2006
    Сообщения:
    272
    Симпатии:
    0
    Адрес:
    Gatchina
    Издеваешься? :)
     
  3. sylex

    sylex Активный пользователь

    С нами с:
    9 ноя 2008
    Сообщения:
    625
    Симпатии:
    0
    Адрес:
    Омск
    PHP:
    1. <html><body><?php $var = 'Привет!'; echo $var ?></body></html>
    Или:
    PHP:
    1. <?php $var = 'Привет!' ?><html><body><?php echo $var ?></body></html>
    Или:
    PHP:
    1. <?php $var = 'Привет!' ?><html><body><?=$var?></body></html>
     
  4.  
  5. sylex

    sylex Активный пользователь

    С нами с:
    9 ноя 2008
    Сообщения:
    625
    Симпатии:
    0
    Адрес:
    Омск
    оО
     
  6. sylex, все намного хуже, чем ты думаешь...
     
  7. ShamahN

    ShamahN Активный пользователь

    С нами с:
    10 апр 2007
    Сообщения:
    1.449
    Симпатии:
    0
    Адрес:
    г.Волгодонск Роствской обл.
    аааааа... афтар жжет!!!! :) под столом....
     
  8. Mete0

    Mete0 Активный пользователь

    С нами с:
    18 дек 2006
    Сообщения:
    272
    Симпатии:
    0
    Адрес:
    Gatchina
    флоппик
    У него нервы не выдержали? :)
     
  9. Нет, он издевается. Последнее время. В армию забирают. Ну, или может девушка ушла.
     
  10. Mete0

    Mete0 Активный пользователь

    С нами с:
    18 дек 2006
    Сообщения:
    272
    Симпатии:
    0
    Адрес:
    Gatchina
    флоппик
    Ясно.
     
  11. ShamahN

    ShamahN Активный пользователь

    С нами с:
    10 апр 2007
    Сообщения:
    1.449
    Симпатии:
    0
    Адрес:
    г.Волгодонск Роствской обл.
    ShamahN
    Зарегистрирован: 10.04.2007
    Сообщения: 587
     
  12. [vs]

    [vs] Суперстар
    Команда форума Модератор

    С нами с:
    27 сен 2007
    Сообщения:
    10.559
    Симпатии:
    632
    Троль с ИИ? о_0
     
  13. [vs]

    [vs] Суперстар
    Команда форума Модератор

    С нами с:
    27 сен 2007
    Сообщения:
    10.559
    Симпатии:
    632
  14. Mr.M.I.T.

    Mr.M.I.T. Старожил

    С нами с:
    28 янв 2008
    Сообщения:
    4.586
    Симпатии:
    1
    Адрес:
    у тебя канфетка?
    Наверника тут не всё так просто =))
    PHP:
    1. <?
    2. class printer {
    3.  public static $buffer;
    4.      static function buffer($var,$code='0') {
    5.               self::$buffer[$code].=$var;
    6.      }
    7.      static function Resulting($code='0',$return=0) {
    8.              if ($return)
    9.                   return self::$buffer[$code];
    10.              else
    11.                   print self::$buffer[$code];
    12.     }        
    13. }
    14. ?>
     
  15. ShamahN

    ShamahN Активный пользователь

    С нами с:
    10 апр 2007
    Сообщения:
    1.449
    Симпатии:
    0
    Адрес:
    г.Волгодонск Роствской обл.
    Mr.M.I.T.
    думаю, именно это искал автор :):)
     
  16. ShamahN

    ShamahN Активный пользователь

    С нами с:
    10 апр 2007
    Сообщения:
    1.449
    Симпатии:
    0
    Адрес:
    г.Волгодонск Роствской обл.
    [vs]
    а я повелся :):)
     
  17. sylex

    sylex Активный пользователь

    С нами с:
    9 ноя 2008
    Сообщения:
    625
    Симпатии:
    0
    Адрес:
    Омск
    Надеюсь тебе удалось решить проблему!! :)
     
  18. dAllonE

    dAllonE Guest

    Mr.M.I.T., нечего плодить негибкие решения, если давно уже реализованно на паттернах:

    PHP:
    1.  
    2. <?php
    3. /********************************************************************
    4. Model-View-Controller implementation according to POSA
    5. (Pattern-Oriented Software Architecture
    6.   [url=http://www.hillside.net/patterns/books/Siemens/book.html]http://www.hillside.net/patterns/books/ ... /book.html[/url])
    7. ********************************************************************/
    8.  
    9. class HelloWorldController {
    10.     private $model;
    11.     function __construct($model) {
    12.         $this->model = $model;
    13.     }
    14.  
    15.     function handleEvent($args) {
    16.         $this->model->setStrategy($args[2]);
    17.         $this->model->addText($args[1]);
    18.     }
    19. }
    20.  
    21.  
    22. class HelloWorldModel {
    23.     private $text;
    24.     private $observers = array();
    25.     private $strategy;
    26.    
    27.     function attach($observer) {
    28.         $this->observers[] = $observer;
    29.     }
    30.  
    31.     function getData() {
    32.         $facade = new HelloWorldFacade($this->strategy);
    33.         return $facade->getHelloWorld().$this->text."\n";
    34.     }
    35.  
    36.     function addText($text='') {
    37.         $this->text = $text;
    38.         $this->notify();
    39.     }
    40.  
    41.     function setStrategy($strategy) {
    42.         $this->strategy = $strategy;
    43.     }
    44.    
    45.     function notify() {
    46.         foreach ($this->observers as $observer) {
    47.             $observer->update();
    48.         }
    49.     }
    50. }
    51.  
    52. class HelloWorldView {
    53.     private $model;
    54.  
    55.     function initialize($model) {
    56.         $this->model = $model;
    57.         $model->attach($this);
    58.         return $this->makeController();
    59.     }
    60.  
    61.     function makeController() {
    62.         return new HelloWorldController($this->model);
    63.     }
    64.  
    65.     function update() {
    66.         $this->display();
    67.     }
    68.  
    69.     function display() {
    70.         echo $this->model->getData();
    71.     }
    72. }
    73.  
    74.  
    75. /*********************************************************************
    76. "Business logic"
    77. ********************************************************************/
    78.  
    79. class HelloWorld {
    80.    function execute() {
    81.        return "Привет";
    82.    }
    83. }
    84.  
    85. class HelloWorldDecorator {
    86.    private $helloworld;
    87.    function __construct($helloworld) {
    88.        $this->helloworld = $helloworld;
    89.    }
    90.  
    91.    function execute() {
    92.        return $this->helloworld->execute();
    93.    }
    94. }
    95.  
    96. abstract class HelloWorldEmphasisStrategy {
    97.     abstract function emphasize($string);
    98. }
    99.  
    100. class HelloWorldBangEmphasisStrategy extends HelloWorldEmphasisStrategy {
    101.     function emphasize($string) {
    102.        return $string."!";
    103.     }
    104. }
    105.  
    106. class HelloWorldRepetitionEmphasisStrategy extends HelloWorldEmphasisStrategy {
    107.     function emphasize($string) {
    108.        return $string." and ".$string." again";
    109.     }
    110. }
    111.  
    112. class HelloWorldEmphasizer extends HelloWorldDecorator {
    113.    private $strategy;
    114.    function HelloWorldEmphasizer($helloworld,$strategy) {
    115.        $this->strategy = $strategy;
    116.        parent::__construct($helloworld);
    117.    }
    118.  
    119.    function execute() {
    120.        $string = parent::execute();
    121.        return $this->strategy->emphasize($string);
    122.    }
    123. }
    124.  
    125. class HelloWorldStrategyFactory {
    126.     static function make($type) {
    127.         if ($type == 'repetition') return self::makeRepetitionStrategy();
    128.         return self::makeBangStrategy();
    129.     }
    130.  
    131.     static function makeBangStrategy() {
    132.         return new HelloWorldBangEmphasisStrategy;
    133.     }
    134.     static function makeRepetitionStrategy() {
    135.         return new HelloWorldRepetitionEmphasisStrategy;
    136.     }
    137. }
    138.  
    139. class HelloWorldFormatter extends HelloWorldDecorator {
    140.    function execute() {
    141.        $string = parent::execute();
    142.        return $string."\n";
    143.    }
    144. }
    145.  
    146. class HelloWorldFacade {
    147.     private $strategy;
    148.     function __construct($strategyType) {
    149.         $this->strategy = HelloWorldStrategyFactory::make($strategyType);
    150.     }
    151.  
    152.     function getHelloWorld() {
    153.         $formatter = new HelloWorldFormatter(
    154.                 new HelloWorldEmphasizer(
    155.                     new HelloWorld,$this->strategy));
    156.         return $formatter->execute();
    157.     }
    158. }
    159.  
    160. $model = new HelloWorldModel;
    161. $view = new HelloWorldView;
    162. $controller = $view->initialize($model);
    163. $controller->handleEvent($_SERVER['argv']);
    164.  
    165. ?>
    166.  
     
  19. adw0rd

    adw0rd Активный пользователь

    С нами с:
    10 ноя 2008
    Сообщения:
    12
    Симпатии:
    0
    Адрес:
    Санкт-Петербург
    PHP:
    1. <html><body><?php echo $var = 'Привет!'; ?></body></html>
    :)
     
  20. sylex

    sylex Активный пользователь

    С нами с:
    9 ноя 2008
    Сообщения:
    625
    Симпатии:
    0
    Адрес:
    Омск
    жесть :)
     
  21. dAllonE, нет интерфейсов. Низачод.
     
  22. sylex

    sylex Активный пользователь

    С нами с:
    9 ноя 2008
    Сообщения:
    625
    Симпатии:
    0
    Адрес:
    Омск
    PHP:
    1. <script language="php"> echo $var; </script>
     
  23. sylex

    sylex Активный пользователь

    С нами с:
    9 ноя 2008
    Сообщения:
    625
    Симпатии:
    0
    Адрес:
    Омск
    PHP:
    1. <?php print $var ?>
     
  24. dAllonE

    dAllonE Guest

    флоппик, обязательно отпишусь в багтрек разработчикам.