-2

So I have this HTML:

<form accept-charset="utf-8" method="post" action="result.php" target="_blank">
  <select name="date-shamsi-week-day">
    <option value="شنبه" selected>شنبه</option>
    <option value="یکشنبه" title="something">یکشنبه</option>
  </select>
</form>

and I want to print it in a variable in another file like this:

<?php 
  $dateshamsiweekday = $_POST['date-shamsi-week-day'];
  echo $dateshamsiweekday;
?>

it works just fine but as you can see I need to use UTF-8 (persian characters) and it doesn't echo anything when looking at the output.

ٍEDIT: it's a shame but since it's my first day learning php I had a syntax error because I used ، after my variable name and it got nothing to do with UTF-8 Characters.

4

3 回答 3

1

您当前的 PHP 语法是错误的。尝试将其更改为:

<?php 
    $dateshamsiweekday = $_POST['date-shamsi-week-day'];
    echo '<span>'.$dateshamsiweekday.'</span>';
?>
于 2013-11-12T11:51:43.113 回答
1

<span>标签需要在 PHP 代码块之外;它们不是 PHP,而是 HTML。

<?php 
  $dateshamsiweekday = $_POST['date-shamsi-week-day'];
?><span><?= $dateshamsiweekday ?></span>

或者,如果您在 5.4.0 之前使用 PHP 并且没有short_open_tags启用,

<?php 
  $dateshamsiweekday = $_POST['date-shamsi-week-day'];
?><span><?php echo $dateshamsiweekday ?></span>

<?php无论哪种方式,如果您之后想要更多代码,则必须打开另一个。

于 2013-11-12T11:56:14.543 回答
-2
<head>
<meta http-equiv = "Content-Type" content = "application/xhtml+xml; charset=utf-8"/> 
<title>Untitled Document</title>
</head>
<?php
if(isset($_POST['submit'])) {
    $date_day= $_POST['date-shamsi-week-day'];
    echo $date_day;
}
?> 

<form  method="post" action="">
  <select name="date-shamsi-week-day">
    <option value="&#1588;&#1606;&#1576;&#1607;" selected>&#1588;&#1606;&#1576;&#1607;</option>
    <option value="&#1740;&#1705;&#1588;&#1606;&#1576;&#1607;" title="something">&#1740;&#1705;&#1588;&#1606;&#1576;&#1607;</option>
  </select>
  <input type="submit" name="submit" value="Submit"/>
</form>
于 2013-11-12T12:06:31.390 回答