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.
Your current PHP syntax is wrong. Try changing it to this:
<?php
$dateshamsiweekday = $_POST['date-shamsi-week-day'];
echo '<span>'.$dateshamsiweekday.'</span>';
?>
The <span>
tags need to be outside the PHP code block; they're not PHP, but HTML.
<?php
$dateshamsiweekday = $_POST['date-shamsi-week-day'];
?><span><?= $dateshamsiweekday ?></span>
or, if you're using PHP before 5.4.0 and don't have short_open_tags
enabled,
<?php
$dateshamsiweekday = $_POST['date-shamsi-week-day'];
?><span><?php echo $dateshamsiweekday ?></span>
Either way, you must then open up another <?php
if you want more code after that.
<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="شنبه" selected>شنبه</option>
<option value="یکشنبه" title="something">یکشنبه</option>
</select>
<input type="submit" name="submit" value="Submit"/>
</form>