I am using a function I found on Stackoverflow to replace some special characters:
function toASCII( $str )
{
return strtr(utf8_decode($str),
utf8_decode(
'ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝŐŰßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿőű'),
'SOZsozYYuAAAAAAACEEEEIIIIDNOOOOOOUUUUYOUsaaaaaaaceeeeiiiionoooooouuuuyyou');
}
However, when I try the functionality in HTML I do not get the desired result. HTML code:
<?php
$test = 'ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝŐŰßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿőű';
$test1 = toASCII($test);
?>
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<?php echo $test."<br>";
echo $test1;
?>
</body>
</html>
Result in Browser:
ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝŐŰßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿőű
uuuuuuuYuAAAAAAACEEEEIIIIDNOOOOOOUUUUYuusaaaaaaaceeeeiiiionoooooouuuuyyuu
Any ideas why some characters are shown as u instead of the desired one?
Note: I would prefer to avoid using setlocale since it would required additional changes in the code.
When you use strtr() with three arguments, it operates with bytes and not with multibyte characters (see http://php.net/manual/en/function.strtr.php#111270). Instead you have to give an array that contains an exact mapping.
This would be a solution for your case:
<?php
function mbStringToArray( $str ) {
return preg_split('//u', $str, -1, PREG_SPLIT_NO_EMPTY);
}
function toASCII( $str ) {
$map = array_combine(
mbStringToArray('ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝŐŰßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿőű'),
mbStringToArray('SOZsozYYuAAAAAAACEEEEIIIIDNOOOOOOUUUUYOUsaaaaaaaceeeeiiiionoooooouuuuyyou')
);
return strtr($str,$map);
}
$test = 'ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝŐŰßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿőű';
$test1 = toASCII($test);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<?php
echo $test."<br>";
echo $test1;
?>
</body>
</html>
Output:
ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝŐŰßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿőű
SOZsozYYuAAAAAAACEEEEIIIIDNOOOOOOUUUUYOUsaaaaaaaceeeeiiiionoooooouuuuyyou
Related
I am trying to pass a variable from the controller to the view, but it is displaying the following message:
Undefined variable.
Controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class QuizController extends Controller
{
public function getUrl($url = null) {
$bandeira = '1';
$bandeira2 = '2';
if ($url == '1') {
return view('quiz')->with($bandeira);
} elseif ($url == '2') {
return view('quiz')->with($bandeira2);
} else {
return view('home');
}
}
}
View
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Copa do Mundo 2018</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
</head>
<body>
<div id="page-wrap">
<h1>Quiz Copa do Mundo 2018</h1>
<form action="grade.php" method="post" id="quiz">
<ol>
<li>
<h3> ?</h3>
#if($bandeira == '1')
<img src="{{ asset('img/espanha.jpg') }}" alt=""/>
#elseif($bandeira == '2')
<img src="{{ asset('img/argentina.jpg') }}" alt=""/>
#endif
When passing information in this manner, the data should be an array with key / value pairs. Inside your view, you can then access each value using its corresponding key, such as <?php echo $key; ?>.
Correction of your code:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class QuizController extends Controller
{
public function getUrl($url = null) {
$data_to_view['bandeira'] = url;
if ($url != null) {
return view('quiz')->with($data_to_view);
} else {
return view('home');
}
}
}
In your view:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Copa do Mundo 2018</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
</head>
<body>
<div id="page-wrap">
<h1>Quiz Copa do Mundo 2018</h1>
<form action="grade.php" method="post" id="quiz">
<ol>
<li>
<h3> ?</h3>
#if($bandeira == '1')
<img src="{{ asset('img/espanha.jpg') }}" alt=""/>
#elseif($bandeira == '2')
<img src="{{ asset('img/argentina.jpg') }}" alt=""/>
#endif
write your variable like this
$bandeira['bandeira'] = 1;
return view('quiz')->with($bandeira);
I think you should write your getUrl method just like this
return view('home', ['bandeira' => $url]); and no if statement required
change your view page
<?php
if(isset($bandeira) && $bandeira==1)
{
// your code here....
}
else if(isset($bandeira) && $bandeira==2)
{
// your code here....
}
?>
I think it is helpful for you
my data, which I try to pass from my controller to the view is apparently ignored. The console doesn't output any errors. Can somebody point me to the apparently obvious mistake I did?
Controller
#RequestMapping("/notes")
public String index(ModelMap model) {
String test = "Hello Felix";
model.addAttribute("hello", test);
return "notes";
}
View
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%# page contentType="text/html; charset=UTF-8" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Notes</title>
</head>
<body>
<h1>${hello}</h1>
</body>
</html>
HTML Source
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Notes</title>
</head>
<body>
<h1></h1>
</body>
</html>
You need to return the model, something like the following should work:
Map model = ...
model.put(name, value);
return new ModelAndView(view, model);
Error Line 18, Column 19: document type does not allow element "div" here; assuming missing "object" start-tag
Please see the page source below
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta name="keywords" content="Karnataka,Bangalore_Rural,Healthcare,Office_Assistant,Kerala,Ernakulam,IT_Hardware_Networking,Engineer,Sales___Marketing,Executive,Maharashtra,Mumbai_City,Retailing,Manager,Kollam,CRM_CallCentres_BPO_ITES_Med.Trans,Customer_Care,Hotel_Travel_Tourism_Airlines_Hospitality,Front_Office_Staff,Andhra_Pradesh,Hyderabad,IT_Software,Java_Developer,Pathanamthitta,Manufacturing_Industrial,Educational_Training,Teacher,Engineering_Projects"/>
<meta name="description" content="The best job oriented resume sharing system. Create and Publish your online resumes for FREE. Search and apply your dream jobs for FREE. Post your jobs for FREE."/>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<div id="fb-root"></div>
I do believe you need to put the < div > inside a < body > section.
Hello and thank you for reading my post.
Here is what I basically want to do:
in a first HTML page ("parent.html"), there is a button ;
when a user clicks the button a new window pops up ("child.html")
AND the contents of a "div" element in the child window is updated.
The final action is unsuccessful under "Firefox" and "Chrome".
parent.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Parent window document</title>
</head>
<body>
<input
type="button"
value="Open child window document"
onclick="openChildWindow()" />
<script type="text/javascript">
function openChildWindow()
{
var s_url = "http://localhost:8080/projectroot/child.html";
var s_name = "ChildWindowDocument";
var s_specs = "resizable=yes,scrollbars=yes,toolbar=0,status=0";
var childWnd = window.open(s_url, s_name, s_specs);
var div = childWnd.document.getElementById("child_wnd_doc_div_id");
div.innerHTML = "Hello from parent wnd";
}
</script>
</body>
</html>
child.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Parent window document</title>
</head>
<body>
<div id="child_wnd_doc_div_id">child window</div>
</body>
</html>
IE9 => it works.
Firefox 13.0.1 => it doesn't work. Error message: "div is null".
Chrome 20.0.1132.47 m => doesn't work.
Do you understand that behaviour?
Can you help me make it work in these three cases?
Thank you and best regards.
I think that the window/document is not loaded at the time when you try to access the elements from it. You can do something like
childWnd.onload = function() {
var div = childWnd.document.getElementById("child_wnd_doc_div_id");
div.innerHTML = "Hello from parent wnd";
}
Also you can take a look at the mdn doc.
A better approach to the problem may be to do the changes in the 'child'. You can access the parent window with window.opener. But you should keep in mind that the parent window could be closed so you should consider some type of local storage (e.g. cookie).
I simply cannot find an object in DOM using Firebug (FF).
I want to see elrteOptions object in DOM. I right-click "Inspect Element" on the page, going to DOM tab and typing elrteOptions in the search box. No results.
How to I see it? =)
Thanks.
Code is as simple as:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>some</title>
<script src='js/jquery.min.js' type='text/javascript'></script>
<script type='text/javascript'>
$(document).ready(function() {
var elrteOptions = {
cssClass : 'el-rte',
lang : 'ru',
toolbar : 'maxi',
cssfiles : ['styles/elrte-inner.css']
}
});
</script>
</head>
<body>
test
</body>
</html>
Looks like it had something to do with the browser (Firefox 9.0.1).
After complete re-install: objects started to appear normally.