$input = new SimpleXMLElement(/* ... */);
foreach ($input->xpath('//product') as $product) {
foreach ($product->xpath('properties/property') as $i => $property) {
$product->addChild('property' . ($i + 1), $property->name->__toString() . ':' . $property->value->__toString());
}
unset($product->properties);
}
$data = 'd1 82 d0 be d1 82 d0 b0 d0 bb d0 b8 d1 82 d0 b0 d1 80 d0 b8 d0 b7 d0 bc 20 d1 87 d0 b8 d1 81 d1 82 d0 be d0 b9 20 d0 b2 d0 be d0 b4 d1 8b 2c d0 b4 d0 b0 20 d0 b7 d0 b4 d1 80 d0 b0 d1 81 d1 82 d0 b2 d1 83 d0 b5 d1 82 20 d0 9f d0 98 d0 9f';
echo hex2bin(str_replace(' ', '', $data)) . PHP_EOL; // тоталитаризм чистой воды,да здраствует ПИП
$groups = [];
$xml = simplexml_load_file('in.xml');
foreach ($xml->xpath('//Группа') as $group) {
$parent = $group->xpath('parent::Группы/parent::Группа/Ид');
$groups[] = [
'id' => $group->{'Ид'}->__toString(),
'name' => $group->{'Наименование'}->__toString(),
'parentID' => count($parent) == 0 ? null : $parent[0]->__toString()
];
}
echo json_encode($groups);
import java.util.stream.Stream;
public class Main {
public static void main(String... args) {
String vowels = "аеёиоуыэюя";
String[] words = {"абра", "кадабра", "интерес", null, "Проверка", "ещё", "логика", "", "Ёж", "Сигнал"};
Stream.of(words).filter(word -> {
return word != null && word.length() > 0 && !vowels.contains(word.substring(0, 1).toLowerCase());
}).forEach(word -> System.out.print(word + " "));
}
}
class A {
public static function __callStatic( $name, $args ) {
return call_user_func( __CLASS__ . '::' . $name . count( $args ), $args );
}
private static function f1( $args ) {
return 'f1: ' . implode( ', ', $args );
}
private static function f2( $args ) {
return 'f2: ' . implode( ', ', $args );
}
}
echo A::f( 1 ) . PHP_EOL; // f1: 1
echo A::f( 2, 3 ) . PHP_EOL; // f2: 2, 3
// echo A::f( 4, 5, NULL ) . PHP_EOL; // PHP 7.0.33 enters an indefinite loop here
public class SomeClass {
public static void main(String... args) {
String com = "0.1 https://sitehere.com/files/ md5hashhere";
List<String> tokens = new ArrayList<>();
try (Scanner scanner = new Scanner(com)) {
while (scanner.hasNext()) {
tokens.add(scanner.next().trim());
}
}
System.out.println("tokens=" + tokens + ", tokens(1)=" + tokens.get(1));
// tokens=[0.1, https://sitehere.com/files/, md5hashhere], tokens(1)=https://sitehere.com/files/
}
}
import java.util.Scanner;
public class Test {
private static String name;
public static void nameInput() {
try (Scanner sc = new Scanner(System.in)) {
System.out.print("What is your name? ");
Test.name = sc.next();
}
}
public static void main(String args[]) {
Test.nameInput();
System.out.println(Test.name);
}
}
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
class WhyAmIHere {
public static void main(String... args) {
List<Character> targets = Arrays.asList(new Character[]{'A', 'E', 'I', 'O', 'U', 'Y'});
Map<Character, Integer> counter = new HashMap<>();
StringBuilder sequence = new StringBuilder();
Random random = new Random();
for (int i = 0; i < 10; i++) {
char c = (char)(random.nextInt(26) + 65);
sequence.append(c);
if (targets.contains(c)) {
counter.put(c, counter.getOrDefault(c, 0) + 1);
}
}
System.err.println("sequence=" + sequence + ", counter=" + counter);
}
}