Removing XML attributes with XML_Serializer - php

Hopefully there's one or two experienced users of the XML_Serializer PEAR class here
I'm parsing an XML file with XML_Serializer
I'm using this PEAR class so that I can grab the entire contents and put it into an array (why is another story for another time)
At the moment it is also taking the attributes and their values of the tags like so:
<prod id="88966064" pre_order="no" web_offer="no" in_stock="no" stock_quantity="0">
<pId>608</pId>
<isbn>0000000000000</isbn>
And adding them to the returned array like this:
XML_Serializer_Tag] => Array(
[id] => 88966064
[pre_order] => no
[web_offer] => no
[in_stock] => no
[stock_quantity] => 0
)
Are there any options in XML_Serializer that allows me to use the XML data without the attributes and just the tags and the data inbetween them, ie only?
<pId>608</pId>
<isbn>0000000000000</isbn>
The data is dynamic so a solution of removing them individually is no goer

XML_Unserializer defaults its 'parseAttributes' option to FALSE [1]. Try to explicitly set it to FALSE and see if that helps.
[1] -- https://pear.php.net/manual/en/package.xml.xml-serializer.xml-unserializer.options.php

Related

How to extract the name from text in PHP

I want to extract the name from a paragraph or text content. I am using PHP. I tried to extract the name from below library.
https://packagist.org/packages/php-text-analysis/php-text-analysis
https://packagist.org/packages/php-text-analysis/php-text-analysis
$text = "my name is maneesh, and my friend name is Paritosh";
$freqDist = freq_dist(tokenize($text));
print_r($freqDist); die;
My expected output is : maneesh, Paritosh
Actual result is getting only frequency of word:
(
[my] => 2
[name] => 2
[is] => 2
[maneesh] => 1
[and] => 1
[friend] => 1
[Paritosh] => 1
)
If you are going to use the library you mentioned, you have to train your model. That means, fill them with many possible ways in which people can say their name. But even so, I wouldn't be perfect (depends on how well you trained your model).
Moreover, you are getting only frequency of words because that's the analysis you requested with the method freq_dist. I think you have to use corpus analysis for what you want.

How to tidy up custom fields inputs in Wordpress

Hi all looking for a little help.
I've created a site which shows the previous form of soccer teams like so:
This works fine and each letter is output by PHP as an image.
The problem is that the only way I could get my head round it to work it out was to create a custom field of checkboxes in Wordpress like so:
What would probably work better would just to have a textbox on the backend where I could just type in the form like "WLDWW" and then the front end display as necessary.
Problem is that I'm not entirely sure where to start with PHP for it to read each individual letter that I put into the textbox and translate that into the image needed at the front end.
Any ideas?
Thanks in advance
Take a look at str_split(). (see here)
$string = "WLWLLW";
$result = str_split($string);
This will output:
Array
(
[0] => W
[1] => L
[2] => W
[3] => L
[4] => L
[5] => W
)
Then you can iterate through the array and display as needed, if you want to use PHP. Of course, I don't know how you've implemented it exactly or how it uses Wordpress, so you may have to make some adjustments as needed.

Does x-Cart strips tags from posted data?

I send data from form, where the textarea contains html tags. On PHP side I do not see them, using:
echo "<pre>";
print_r( $_POST );
echo "</pre>";
exit();
I get:
Where have paragraph tags gone?
In source code they are clearly gone:
<pre>Array
(
[mode] => save_product
[id] => 1
[title] => Banana Shake
[categoryid] => 1
[serving] => 34.50
[orderby] => 10
[intro] => Intro
[instructions] => Empty contents of packet into a shaker or blender, add 200-240ml of cold water and shake/mix until fully dissolved.
Consume within 10 minutes for full nutritional benefit.
...</pre>
EDIT
I am using x-Cart's engine to manipulate data, could be the x-Cart strips those tags.
The solution was to set trusted variables at beginning of the script this way:
define('USE_TRUSTED_POST_VARIABLES', 1);
$trusted_post_variables = array('intro', 'instructions');
That way x-cart won't strip any tags.
Thanks for the help and sorry for the confusion.
EDIT: this answer is written on the presumption that you are not using a framework or other method that strips HTML tags from your post.
Your paragraph tags are still there. Since you're printing them in the browser, the browser is interpreting them as real <p> tags. If you were to look at the page's source code, you'd see the tags. (Google "<your browser name> view page source" for instructions on how to do this.)
You could also use htmlentities($_POST['instructions]) or htmlspecialchars($_POST['instructions]) to change the HTML tags to entities, which will cause them to be printed to the browser.
htmlentities()
htmlspecialchars()

Retrieving notes from Evernote API using tags in PHP

I'm using Evernote's PHP SDK and I need to retrieve a list of tagged notes.
When I filter by keyword or notebook giud it works, but as soon as I set tagGuids i get empty list.
Here's sample code:
$noteFilter=new EDAM\NoteStore\NoteFilter();
#For the sake of this example, I'm just getting all existing tags
#and adding them to filter so it should:
$tags=$noteStore->listTags($token);
$noteFilter->tagGuids=Array();
foreach($tags as $tag){
$noteFilter->tagGuids[]=$tag->guid;
}
$notes=$noteStore->findNotes($token,$noteFilter,0,20);
I have notes with tags. But this is what i get in result, an empty list:
EDAM\NoteStore\NoteList Object
(
[startIndex] => 0
[totalNotes] => 0
[notes] => Array
(
)
[stoppedWords] =>
[searchedWords] =>
[updateCount] => 139
)
Actually, you can't do this kind of search. Using the tagGuids property with - let's say - 2 tags will lead to search for notes containing these 2 tags at the same time.
It's an 'AND' search, not an 'OR' search.
One option would be to make several searches, each with one tag and merging the results...
Not optimal but I'm afraid it's the only solution you have.
You may find some help here : https://dev.evernote.com/doc/articles/search_grammar.php
BTW, the findNotes methods is deprecated. You should use the findNotesMetadata method :
$resultSpec = new \EDAM\NoteStore\NotesMetadataResultSpec();
$resultSpec->includeTitle;
$resultSpec->includeTagGuids;
$notes=$noteStore->findNotesMetadata($authToken,$noteFilter,0,20, $resultSpec);

cakephp sending encrypted data to library from Controller

While working with the cakephp, I found an issue mentioned below.
Fetched the encrypted field info from DB (encrypted using Security::rijndael)
Passed this whole data as an array format to the custom Library(Own created lib).
When i echoed the data in lib as well in controller I amazed to see the result. The value (encrypted one) are showing blank in the lib. Is I missed anything in codding? I searched on google but didn't get the satisfactory answer, Please help me out. Your help will really be appreciated.
Here is result i am getting in controller and Library respectively
Array
(
[0] => Array
(
[value] => s�i�(�RTf���cBЉF� | �r�n#ô�
)
)
Array
(
[0] => Array
(
[value] =>
)
)
Check your character encoding; a place I worked at ran into a similar issue and it was due to our db trying to encode characters it did not support. UTF-8 generic is a, well, generic encoding type.

Categories