Skip to content

Commit

Permalink
Adding support for <?php echo
Browse files Browse the repository at this point in the history
  • Loading branch information
zombor committed May 24, 2010
1 parent 7f0d1d9 commit 36acc6d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions classes/kohana/view.php
Expand Up @@ -59,7 +59,7 @@ protected function capture($kohana_view_filename, array $kohana_view_data)
{
$data = file_get_contents($kohana_view_filename);

$regex = '/<\?=(.+?)\?>/';
$regex = '/<\?(\=|php echo)(.+?)\?>/';
$data = preg_replace_callback($regex, array($this, '_escape_val'), $data);

// Load the view within the current scope
Expand All @@ -86,10 +86,10 @@ protected function capture($kohana_view_filename, array $kohana_view_data)
*/
protected static function _escape_val($matches)
{
if (substr($matches[1], 0, 1) != '!') // Escape the data
return '<?php echo html::chars('.$matches[1].'); ?>';
if (substr(trim($matches[2]), 0, 1) != '!') // Escape the data
return '<?php echo html::chars('.$matches[2].'); ?>';
else // Remove the "turn off escape" character
return '<?php echo '.substr($matches[1], 1, strlen($matches[1])-1).'; ?>';
return '<?php echo '.substr(trim($matches[2]), 1, strlen($matches[2])-1).'; ?>';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion views/complex.php
Expand Up @@ -5,7 +5,7 @@
<title><?=$title?></title>
</head>
<body>
<h1><?=$title?></h1>
<h1><?php echo $title?></h1>
<p>Here are all my <?=$things?>:</p>
<ul>
<?php foreach ($tests as $test):?>
Expand Down

0 comments on commit 36acc6d

Please sign in to comment.