Board index   FAQ   Search  
Register  Login
Board index php forum :: HTML HTML Basics

PHP to HTML

Discussing Html . Code , Software , other

Moderators: macek, egami, gesf

PHP to HTML

Postby JenL » Mon Jan 16, 2012 3:47 am

Hello,

We've made a script. But we don't know how to use it in a HTML page, We tried some things but it doesn't work. The mention is to make a script to translate. Not really translate but like the caesarcode, ( A=B etc.) We want to put the script working on diferent tables. The user can choose the rotation 1 til 25. this is our php code:


[php]
class CaesarCode {
private static $alfabetUpper;
private static $alfabetLower;

private $steps;

private function _getNewPosition($originalPosition) {
return ($originalPosition + $this->steps) % 26;
}

private function _getCharFromArray($char, $fromArray) {
if (($charKey = array_search($char, $fromArray)) !== false) {
return $fromArray[$this->_getNewPosition($charKey)];
}
return false;
}

private function _translateChar($char) {
$translatedChar = $this->_getCharFromArray($char, $this->_getAlfabetUpper());
if ($translatedChar === false) {
$translatedChar = $this->_getCharFromArray($char, $this->_getAlfabetLower());
}
return $translatedChar;
}

private function _getAlfabetUpper() {
if (empty(self::$alfabetUpper)) {
self::$alfabetUpper = range('A', 'Z');
}
return self::$alfabetUpper;
}

private function _getAlfabetLower() {
if (empty(self::$alfabetLower)) {
self::$alfabetLower = range('a', 'z');
}
return self::$alfabetLower;
}

public function __construct($steps) {
$this->steps = $steps;
}

public function translate($string) {
$encr = '';
foreach (str_split($string) as $key => $char) {
if (($newChar = $this->_translateChar($char)) !== false)
$char = $newChar;
$encr .= $char;
}
return $encr;
}
}
[/php]

And this is how it has to look like:

[php]
<?php
include 'caesarcodephp.php';
$caesarCode = new CaesarCode( 1 );
$result = $caesarCode->translate( 'ABC' );
?>
<!doctype html>
<html>
<head>
<title>oefen</title>
</head>
<body>
<table border="1">
<tr>
<tr><td>Rotatie:</td>
<td>
<select>
<option value ="1"><?php $caesarCode= new CaesarCode( 1 ); ?> 1 </option>
<option value ="2"><?php $caesarCode= new CaesarCode( 2 ); ?>2
</option>
<option value ="3"><?php $caesarCode= new CaesarCode( 3 ); ?>3</option>
<option value ="4"><?php $caesarCode= new CaesarCode( 4 ); ?>4</option>
</select>
</tr>
<tr>
<textarea rows="10" cols="20" style="overflow:hidden;">
<?php echo $caesarCode->translate( 'XYZ' ); ?>
</textarea>
<p style="font-size:10px;"></p>
<textarea rows="10" cols="20" style="overflow:hidden;">
Gecodeerde tekst
</textarea>
<p style="font-size:10px;"></p>
</tr>
<tr>
<td>Resultaat</td>
<td><?php echo $result ?></td>
</tr>
</table>
</body>
</html>


[/php]


I hope you can help us! :D
Greetz!

Jeanine and Liselotte
JenL
New php-forum User
New php-forum User
 
Posts: 1
Joined: Mon Jan 16, 2012 3:39 am

Re: PHP to HTML

Postby engrmudasirmalik » Thu Feb 02, 2012 4:29 am

User avatar
engrmudasirmalik
New php-forum User
New php-forum User
 
Posts: 14
Joined: Wed Jan 11, 2012 11:39 am
Location: Bahawalpur Pakistan

Re: PHP to HTML

Postby xeniar » Sat Feb 04, 2012 2:15 pm

PHP cannot and will not work in a .HTML or .HTM file. PHP only works in .php files.

However, HTML works fine in .php files so anything you can do in a .HTML you can do in a .PHP, plus all the added benefit of being able to use PHP... 8)
xeniar
New php-forum User
New php-forum User
 
Posts: 67
Joined: Tue Jan 24, 2012 1:54 pm

Re: PHP to HTML

Postby Alberta » Thu Mar 29, 2012 12:11 am

PHP and HTML interact a lot: PHP can generate HTML, and HTML can pass information to PHP. Before reading these faqs, it's important you learn how to retrieve variables from external sources. The manual page on this topic includes many examples as well. Pay close attention to what register_globals means to you too.
____________________________
Alberta
New php-forum User
New php-forum User
 
Posts: 5
Joined: Thu Mar 29, 2012 12:04 am

Re: PHP to HTML

Postby grbrains » Sun Apr 08, 2012 10:29 pm

as per your code, please try on .PHP file instead of .HTML file. may be it will be help.

Thanks
-------------
grbrains
New php-forum User
New php-forum User
 
Posts: 12
Joined: Sat Mar 03, 2012 11:31 pm
Location: Ahmedabad, India

Re: PHP to HTML

Postby freshnet » Mon Apr 09, 2012 2:21 am

xeniar wrote:PHP cannot and will not work in a .HTML or .HTM file. PHP only works in .php files.

However, HTML works fine in .php files so anything you can do in a .HTML you can do in a .PHP, plus all the added benefit of being able to use PHP... 8)


fyi that's actually not correct. You can get PHP to work in an html file by modifying your .htaccess file.
User avatar
freshnet
php-forum Active User
php-forum Active User
 
Posts: 278
Joined: Tue Feb 22, 2011 8:19 am
Location: Canada

Re: PHP to HTML

Postby OSDIcompany » Mon Apr 16, 2012 11:18 pm

try with .php may this will help to short out this issue.
OSDIcompany
New php-forum User
New php-forum User
 
Posts: 2
Joined: Mon Apr 16, 2012 10:52 pm


Return to HTML Basics

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron