App.lang = 'ru'; // app = вымышленный объект
<span class="client__title" data-translate="client_title"></span>
$(function() {
var file = '/locale/' + App.lang + '.json';
// Тут предположим, что response = есть содержимое файла
$.get(file).then(function (response) {
// Идем по всем файлам и заменяем контент
$('[data-translate]').each(function () {
var $elem = $(this),
locKey = $elem.data('translate');
// Если ключ найден
if (response[locKey]) {
$elem.html(response[locKey]);
}
});
});
});
$search_string = preg_replace("/[^A-Za-z0-9А-Яа-я]+$/u", "", $_POST['query']);
$strings = [
'foo',
'фУbar',
'бар',
'53252',
'-x-x-x-x-'
];
foreach ($strings as $string) {
var_dump(preg_replace('/[^A-Za-z0-9А-Яа-я]+/u', '', $string));
}
string(3) "foo"
string(7) "фУbar"
string(6) "бар"
string(5) "53252"
string(4) "xxxx"
<html .... data-ng-controller="MainController as ctrl">
<title ng-bind="ctrl.title"></title>
angular.module('app', [])
.service('PageTitle', function() {
this.title = 'default';
this.setTitle = function (title) {
this.title = title;
};
this.getTitle = function () {
return this.title;
};
})
.controller('MainCtrl', function(PageTitle) {
PageTitle.setTitle('Foo Bar');
})
.directive('title', function (PageTitle) {
return {
restrict: 'E',
link: link
};
function link($scope, $el) {
$scope.$watch(watchFn, updateFn);
function watchFn() {
return PageTitle.getTitle();
}
function updateFn(title) {
$el.html(title);
}
}
});
If you compare a number with a string or the comparison involves numerical strings, then each string is converted to a number and the comparison performed numerically
$('a').on('click', function(event) {
event.preventDefault();
var url = $(this).attr('href');
Router.change(url);
});
// Router.change
function change(url) {
history.pushState(url);
var view = this.getView(url);
ViewManager.setView(view);
var controller = this.getController(url);
controller.dispatch();
}