Cannot get the value of the xml fields - php
Hi i have this xml response that i parse and i can access the third text field, i have parsed it and i even do a var_dump($xmlObj->TerminalCommandResponse->Text); in which i get on screen
object(SimpleXMLElement)#48 (14) {
[0]=> string(4) "BB"
[1]=> string(45) " *** BEST QUOTATION ***"
[2]=> string(52) " FOR THIS ITI"
[3]=> string(48) " *** BF SEGMENTS 1P/2P ***"
...
}
But when i try to directly access:
$XMlText=$xmlObjFourth->TerminalCommandResponse->Text;
var_dump($XMLText[2]);
It doesn't show anything. I even tried a foreach loop in case i get the keys wrong but still the same issue
<terminal:TerminalRsp xmlns:terminal="terminal_v50_0" TransactionId="F09006B80A0759BF61F85144F306F735" ResponseTime="527">
<terminal:TerminalCommandResponse>
<terminal:Text>BB</terminal:Text>
<terminal:Text>*** BEST QUOTATION ***</terminal:Text>
<terminal:Text>FOR THIS ITI</terminal:Text>
<terminal:Text>*** BF SEGMENTS 1P/2P ***</terminal:Text>
<terminal:Text> PSGR PSG DES </terminal:Text>
<terminal:Text>FQG 1 PY2PC 3640 6201 ADT </terminal:Text>
<terminal:Text> GUARANTEED A </terminal:Text>
<terminal:Text>)><</terminal:Text>
</terminal:TerminalCommandResponse>
</terminal:TerminalRsp>
Probably it is a special character or a whitespace that is blocking you, it is an interesting issue here what i think will help for starters
foreach($XMLText as $k=>$tmp)
{
var_dump(preg_replace("/[^a-zA-Z0-9\s+]+/", "", $tmp));
}
this way you can see whats in every field in the XMLText array
Related
Loop through array from NIST API.. Cant get it working
Im working with some data from the NIST CVE Database. Im putting it through the simpleXMLElement array but cant figure out how to loop through it properly. Tried following other threads here but cant it working.. These miltidimensional? arrays break me. Any help would be super great! Here is the array dump: object(SimpleXMLElement)#1 (2) { ["channel"]=> object(SimpleXMLElement)#2 (4) { ["title"]=> string(31) "National Vulnerability Database" ["link"]=> string(41) "https://web.nvd.nist.gov/view/vuln/search" ["description"]=> string(114) "This feed contains the most recent CVE cyber vulnerabilities published within the National Vulnerability Database." ["items"]=> object(SimpleXMLElement)#151 (0) { } } ["item"]=> array(148) { [0]=> object(SimpleXMLElement)#3 (3) { ["title"]=> string(35) "CVE-2008-6594 (rdf_newsfeed_export)" ["link"]=> string(62) "https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2008-6594" ["description"]=> string(150) "SQL injection vulnerability in the cm_rdfexport extension for TYPO3 allows remote attackers to execute arbitrary SQL commands via unspecified vectors." } [1]=> object(SimpleXMLElement)#4 (3) { ["title"]=> string(26) "CVE-2014-5129 (projectdox)" ["link"]=> string(62) "https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2014-5129" ["description"]=> string(162) "Cross-site scripting (XSS) vulnerability in Avolve Software ProjectDox 8.1 allows remote attackers to inject arbitrary web script or HTML via unspecified vectors." } [2]=> object(SimpleXMLElement)#5 (3) { ["title"]=> string(24) "CVE-2019-9565 (antidote)" ["link"]=> string(62) "https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2019-9565" ["description"]=> string(467) "Druide Antidote RX, HD, 8 before 8.05.2287, 9 before 9.5.3937 and 10 before 10.1.2147 allows remote attackers to steal NTLM hashes or perform SMB relay attacks upon a direct launch of the product, or upon an indirect launch via an integration such as Chrome, Firefox, Word, Outlook, etc. This occurs because the product attempts to access a share with the PLUG-INS subdomain name; an attacker may be able to use Active Directory Domain Services to register that name." } Im using this code but it just echos "item" each time.. $xml = new SimpleXMLElement($apiData); var_dump($xml); $i="0"; foreach ($xml->item as $key => $value) { echo $xml['item']['$i']['link']; // get the CVE link.. echo "KEY:$key Value:$value \r\n"; $i ++; }
You should use the -> notation for getting the link. The array index is what you called the key. So I would name that $i: foreach ($xml->item as $i => $item) { $link = $item->link; echo "Index:$i Link:$link \r\n"; }
How to sort Japanese like Excel
I want to sort Japanese words ( Kanji) like sort feature in excel. I have tried many ways to sort Japanese text in PHP but the result is not 100% like result in excel. First . I tried to convert Kanji to Katakana by using this lib (https://osdn.net/projects/igo-php/) but some case is not same like excel. I want to sort these words ASC けやきの家 高森台病院 みのりの里 My Result : けやきの家 高森台病院 みのりの里 Excel Result: けやきの家 みのりの里 高森台病院 Second I tried other way by using this function mb_convert_kana($text, "KVc", "utf-8"); The sorting result is correct with those text above, but it contain some case not correct 米田病院 米田病院 高森台病院 My result : 米田病院 米田病院 高森台病院 Excel Result: 高森台病院 米田病院 米田病院 Do you guys have any idea about this. (Sorry for my English ) . Thank you
Firstly, Japanese kanji are not sortable. You can sort by its code number, but that order has no meanings. Your using Igo (or any other morphological analysis libraries) sounds good solution, though it can not be perfect. And your first sort result seems fine for me. Why do you want them to be sorted in Excel order? In Excel, if a cell keeps remembering its phonetic notations when the user initially typed on Japanese IME (Input Method Editor), that phonetics will be used in sort. That means, as not all cell might be typed manually on IME, some cells may not have information how those kanji-s are read. So results of sorting Kanji-s on Excel could be pretty unpredictable. (If sort seriously needed, usually we add another yomigana field, either in hiragana or katakana, and sort by that column.) The second method mb_convert_kana() is totally off point. That function is to normalize hiragana/katakana, as there are two sets of letters by historical reason (full-width kana and half-width kana). Applying that function to your Japanese texts only changes kana parts. If that made your expectation satisfied, that must be coincidence. You must define what Excel Japanese sort order your customer requires first. I will be happy to help you if it is clear. [Update] As op commented, mb_convert_kana() was to sort mixed hiragana/katakana. For that purpose, I suggest to use php_intl Collator. For example, <?php // demo: Japanese(kana) sort by php_intl Collator if (version_compare(PHP_VERSION, '5.3.0', '<')) { exit ('php_intl extension is available on PHP 5.3.0 or later.'); } if (!class_exists('Collator')) { exit ('You need to install php_intl extension.'); } $collator = new Collator('ja_JP'); $textArray = [ 'カキクケコ', '日本語', 'アアト', 'Alphabet', 'アイランド', 'はひふへほ', 'あいうえお', '漢字', 'たほいや', 'さしみじょうゆ', 'Roma', 'ラリルレロ', 'アート', ]; $result = $collator->sort($textArray); if ($result === false) { echo "sort failed" . PHP_EOL; exit(); } var_dump($textArray); This sorts hiragana/katakana mixed texts array. Results are here. array(13) { [0]=> string(8) "Alphabet" [1]=> string(4) "Roma" [2]=> string(9) "アート" [3]=> string(9) "アアト" [4]=> string(15) "あいうえお" [5]=> string(15) "アイランド" [6]=> string(15) "カキクケコ" [7]=> string(21) "さしみじょうゆ" [8]=> string(12) "たほいや" [9]=> string(15) "はひふへほ" [10]=> string(15) "ラリルレロ" [11]=> string(6) "漢字" [12]=> string(9) "日本語" } You won't need to normalize them by yourself. Both PHP(though with php_intl extension) and database(such like MySQL) know how to sort alphabets in many languages so you do not need to write it. And, this does not solve the original issue, Kanji sort.
Laravel Alpha to Hiragana with a custom function Note : $modals (laravel models with get() ) alphabets : Hiragana orders Source : https://gist.github.com/mdzhang/899a427eb3d0181cd762 public static function orderByHiranagana ($modals,$column){ $outArray = array(); $alphabets = array("a","i","u","e","o","ka","ki","ku","ke","ko","sa","shi","su","se","so","ta","chi","tsu","te","to","na","ni","nu","ne","no","ha","hi","fu","he","ho","ma","mi","mu","me","mo","ya","yu","yo","ra","ri","ru","re","ro","wa","wo","n","ga","gi","gu","ge","go","za","ji","zu","ze","zo","da","ji","zu","de","do","ba","bi","bu","be","bo","pa","pi","pu","pe","po","(pause)","kya","kyu","kyo","sha","shu","sho","cha","chu","cho","nya","nyu","nyo","hya","hyu","hyo","mya","myu","myo","rya","ryu","ryo","gya","gyu","gyo","ja","ju","jo","bya","byu","byo","pya","pyu","pyo","yi","ye","va","vi","vu","ve","vo","vya","vyu","vyo","she","je","che","swa","swi","swu","swe","swo","sya","syu","syo","si","zwa","zwi","zwu","zwe","zwo","zya","zyu","zyo","zi","tsa","tsi","tse","tso","tha","ti","thu","tye","tho","tya","tyu","tyo","dha","di","dhu","dye","dho","dya","dyu","dyo","twa","twi","tu","twe","two","dwa","dwi","du","dwe","dwo","fa","fi","hu","fe","fo","fya","fyu","fyo","ryi","rye","(wa)","wi","(wu)","we","wo","wya","wyu","wyo","kwa","kwi","kwu","kwe","kwo","gwa","gwi","gwu","gwe","gwe","mwa","mwi","mwu","mwe","mwo"); $existIds = array(); foreach ($alphabets as $alpha){ foreach ($modals as $modal) { if($alpha == strtolower(substr($modal->$column, 0, strlen($alpha))) && !in_array($modal->id,$existIds)) { array_push($outArray,$modal); array_push($existIds,$modal->id); } } } return $outArray; } Call like this : $students = Students::get(); $students = CommonHelper::orderByHiranagana($students,'lastname');
your data could not be encoded because it contains invalid UTF8 characters jms/serializer-bundle symfony
I am trying to serialize the data of -doctrine repository function- result into JSON format, the operation faild... I am using jms/serializer-bundle... I need your help please $em = $this->getDoctrine() ->getManager(); $repository = $em->getRepository('navormvagBundle:Stationpompage'); $data = $repository->find($id); $serializer = $this->container->get('serializer'); $data = $serializer->serialize($data, 'json'); CRITICAL - Uncaught PHP Exception RuntimeException: "Your data could not be encoded because it contains invalid UTF8 characters." at C:\ms4w\Apache\htdocs\ormvagProject\vendor\jms\serializer\src\JMS\Serializer\JsonSerializationVisitor.php line 36 var_dump($data); object(nav\ormvagBundle\Entity\Communes)#358 (21) { ["objectid12":"nav\ormvagBundle\Entity\Communes":private]=> int(14) ["objectid1":"nav\ormvagBundle\Entity\Communes":private]=> int(14) ["objectid":"nav\ormvagBundle\Entity\Communes":private]=> int(461) ["codeCommu":"nav\ormvagBundle\Entity\Communes":private]=> string(13) "04.291.05.11." ["nomCommun":"nav\ormvagBundle\Entity\Communes":private]=> string(6) "OULMES" ["typeCommu":"nav\ormvagBundle\Entity\Communes":private]=> string(1) "R" ["codeProvi":"nav\ormvagBundle\Entity\Communes":private]=> string(6) "04.291" ["codeRegio":"nav\ormvagBundle\Entity\Communes":private]=> string(2) "04" ["pop2014":"nav\ormvagBundle\Entity\Communes":private]=> int(18786) ["m�nages":"nav\ormvagBundle\Entity\Communes":private]=> int(4688) ["etrangers":"nav\ormvagBundle\Entity\Communes":private]=> float(1) ["marocains":"nav\ormvagBundle\Entity\Communes":private]=> int(18785) ["nomCercle":"nav\ormvagBundle\Entity\Communes":private]=> string(6) "Oulmes" ["x":"nav\ormvagBundle\Entity\Communes":private]=> float(441447.171109) ["y":"nav\ormvagBundle\Entity\Communes":private]=> float(310925.203251) ["nomProvin":"nav\ormvagBundle\Entity\Communes":private]=> string(9) "Khemisset" ["shapeLeng":"nav\ormvagBundle\Entity\Communes":private]=> float(146137.539535) ["codeCercl":"nav\ormvagBundle\Entity\Communes":private]=> string(9) "04.291.05" ["shapeLength":"nav\ormvagBundle\Entity\Communes":private]=> float(146137.54067987) ["shapeArea":"nav\ormvagBundle\Entity\Communes":private]=> float(542883719.60999) ["wkbGeometry":"nav\ormvagBundle\Entity\Communes":private]=> string(26344) "SRID=900914;MULTIPOLYGON(((446016.130999997 319730.371199999,446125.634599999 319486.142200001,446254.220299996 319308.2588,446308.889600001 319175.070700001,446355.217600003 319163.748,446550.325000003 319184.854800001,446615.303800002 319184.508400001,446652.349200003 319173.236499999,446762.549800001 319017.605599999,446827.104000002 318961.889600001,446929.385200001 318983.4965,447125.511100002 319137.504700001 )))" }
I got it. m�nages not valid property name of the entity. That's why serializer fired error. Check your property names, file format (must be UTF-8) and also database configuration. Hope, this will be helpful. Good luck.
PHP Mcrypt_decrypt decrypt only parts of the original string
I have a weird problem regarding passing an encrypted string through url. I'm using base64 encryptions from mcrypt() for encryptHTML() and decryptHTML(). I have this piece of code to encrypt: $link_string = http_build_query(array('index_number'=>30843854, 'extra_attendence_id'=>27982423, 'target_temporary_id'=>378492085, 'date'=>'2016-05-06', 'action'=>'OUT', 'target_id'=>390234), '', '&'); $link_string = encryptHTML($link_string); then I passed it through this url: 'localhost/website/controller/action/'.$link_string then I decrypted it with this piece of code: $id = $this->request->param('id'); $id = decryptHTML($id); parse_str($id, $arr_id2); var_dump($arr_id2); I will get these in return, as expected: array(6) { ["index_number"]=> string(8) "30843854" ["extra_attendence_id"]=> string(8) "27982423" ["target_temporary_id"]=> string(9) "378492085" ["date"]=> string(10) "2016-05-06" ["action"]=> string(3) "OUT" ["target_id"]=> string(6) "390234" } The next case is when I still want the encrypted link but I need to attach some other value from DOM element in the page, so I tried to 'localhost/website/controller/action/encrypt='.$link_string.'&DOMvalue=10000' then I modified the decryption with this piece of code: $id = $this->request->param('id'); parse_str($id, $arr_id2); $the_DOMValue = $arr_id2['DOMvalue']; $id = decryptHTML($arr_id2['crypted']); parse_str($id, $arr_id); var_dump($the_DOMValue); echo "<br>"; var_dump($arr_id); But then, I get these in return, to my surprise: string(5) "10000" array(3) { ["index_number"]=> string(13) "58_2016-04-26" ["extra_attendence_id"]=> string(1) "0" ["target_t"]=> string(0) "" } My original string was cut short! Note that the DOMvalue is fine. Then, I checked that right before both decryption, if the given encrypted string is different: on first case of decryptHTML: $id = $this->request->param('id'); var_dump($id); $id = decryptHTML($id); returns: string(224) "zCQnh-rNP2R7h4UHyV5Dm5zp494DIIku5LWN51yYGMXBaHf0gJgEDw8UCuHRZxr-CkjkevHQ70kOPnSBQ9CJP6lZrFone-nDMDJhYlL8330wz+zud8-3tSWvdOLB7je5D-22aX4OrE3zlBYZZZtI-rMT73H0JGIRzZge2GzcZGLwS7Rj+GL5Ym-ET6JEHDShST4etgcQaEYXml-+BZ2+0BQKvubZEBOB" on the second case of decryptHTML: $id = $this->request->param('id'); parse_str($id, $arr_id2); $the_DOMValue = $arr_id2['DOMvalue']; var_dump($arr_id2['crypted']); $id = decryptHTML($arr_id2['crypted']); returns: string(224) "zCQnh-rNP2R7h4UHyV5Dm5zp494DIIku5LWN51yYGMXBaHf0gJgEDw8UCuHRZxr-CkjkevHQ70kOPnSBQ9CJP6lZrFone-nDMDJhYlL8330wz zud8-3tSWvdOLB7je5D-22aX4OrE3zlBYZZZtI-rMT73H0JGIRzZge2GzcZGLwS7Rj GL5Ym-ET6JEHDShST4etgcQaEYXml- BZ2 0BQKvubZEBOB" It looks exactly the same to me, but strangely it was decrypted differently. I of course used the same functions to decrypt both cases... Anybody can shed me some light on this?
passing an encrypted string through url Passing an encrypted string through a URL is a bad idea. Full stop. I'm using base64 encryptions from mcrypt() for encryptHTML() and decryptHTML(). Without seeing what these functions do, this isn't helpful information, but mcrypt should be avoided. Use Libsodium (if you can; otherwise, use OpenSSL) instead. My original string was cut short! It probably treated the + as a space. Using urlencode() would fix one problem, but it wouldn't solve the vulnerability to chosen-ciphertext attacks that using mcrypt introduces into your application in the absence of a Message Authentication Code (MAC).
php xml function requirements
hi i am using the xml function simplexml_load_string for reading the xml string but there is no any output of this function i also use dom function but the same response of this. is there any another method of reading the xml? or is there any modification require on server to enable these function
There are are many reasons why you might end up with no output at all. Some I can think of are: There's a parse error in your script and your php version is not configured to show startup errors. see display_startup_errors and/or add some unconditional output to the script (so that if this output is missing you know the script didn't even reach that statement). The script doesn't reach the statement because of some conditions ( `if (false) { ... } ). Again add some output and/or use a debugger to see if the statement is reached. The string contains something that is not valid xml and therefore the libxml parser gives up and simplexml_load_string() returns false. Test the return value and maybe check the errors libxml may have encountered, see http://docs.php.net/function.libxml-use-internal-errors The SimpleXML module isn't present (though in recent versions of php it's enabled by default). Use extension_loaded() and/or function_exists() to test this. Try it again with a bit more error handling, e.g. <?php // this is only for testing purposes // set those values in the php.ini of your development server if you like // but use a slightly more sophisticated error handling/reporting mechanism in production code. error_reporting(E_ALL); ini_set('display_errors', 1); echo 'php version: ', phpversion(), "\n"; echo 'simplexml_load_string() : ', function_exists('simplexml_load_string') ? 'exists':"doesn't exist", "\n"; $xml = '<a> >lalala </b> </a>'; libxml_use_internal_errors(true); $doc = simplexml_load_string($xml); echo 'errors: '; foreach( libxml_get_errors() as $err ) { var_dump($err); } if ( !is_object($doc) ) { var_dump($doc); } echo 'done.'; should print something like php version: 5.3.2 simplexml_load_string() : exists errors: object(LibXMLError)#1 (6) { ["level"]=> int(3) ["code"]=> int(76) ["column"]=> int(7) ["message"]=> string(48) "Opening and ending tag mismatch: a line 1 and b " ["file"]=> string(0) "" ["line"]=> int(3) } object(LibXMLError)#2 (6) { ["level"]=> int(3) ["code"]=> int(5) ["column"]=> int(1) ["message"]=> string(41) "Extra content at the end of the document " ["file"]=> string(0) "" ["line"]=> int(4) } bool(false) done.