Transformations to string to get the same result - php

I have this project in php in which my goal is to compare data from the database with some data I get from outlook, and if it's the same data i skip to the next row, otherwise I update.
The data in the DB comes like below:
$db = 'Meeting F2F Planung Meetings/Bilas 2018 2017-09-19 10:002017-09-19 12:0000KI Büro'
The data from outlook:
$outlook = 'Meeting F2F Planung Meetings/Bilas 2018<font size="2"><span style="font-size:10pt;"><div class="PlainText"> </div></span></font>2017-09-19 10:002017-09-19 12:0000KI Büro'
What i do is to get the data from outlook look like the one in DB is:
$outlook = (strip_tags(html_entity_decode($outlook)));
I still get the 'Büro' when I transfrom the data from outlook, so when i compare $outlook and $event, they appear as not equal so in my project it updates.
By asking here I got to the code above, but in this case it doesn't seem to work.

Try this
$outlook = utf8_decode(strip_tags(htmlspecialchars_decode($outlook)));
echo $outlook;

Related

Using PHP For Each to save individual results to Redis

I have some code running on my website that uses API calls to pull events from a calendar and show them on my website. The code is fairly simple overall, and works well, however to prevent the code from running every time the page loads, I'm using PHP Redis to save the key data to a Redis List, then a cronjob to run the php code that uses the Redis List to fetch the information from the calendar API, and save the information to Redis.
Everything works fine, except I am using foreach to run through each instance of the Redis List; and it keeps running through all the entries but saving only the last one. What can I do to fix this?
My code:
<?php
function redis_calendar_fetch() {
$redisObj1 = new Redis();
$redisObj1 -> connect('localhost', 6379, 2.5, NULL, 150 );
date_default_timezone_set('America/Edmonton');
$fetcharray = $redisObj1-> smembers('fetch_list');
$effectiveDate = date('Y-m-d', strtotime('+12 months'));
$application_id = "REDACTED";
$secret = "REDACTED";
$fafull = array();
foreach($fetcharray as $faraw) {
$fa1 = json_decode($faraw);
$fa2 = json_decode(json_encode($fa1), true);
$fafull[] = $fa2;
}
$redisObj1 -> close(); // This code all works perfectly, and returns the Redis List results in an array that can be used by foreach
foreach($fafull as $fa) {
$redisObj = new Redis();
$redisObj -> connect('localhost', 6379, 2.5, NULL, 150 );
// After this, I run through all the array data, pull data & process it properly. I have omitted this from this question because it is long and arduous, and runs perfectly fine.
// Right before this, an array called $redisarray is created that contains all the relevant event data //
$redisarrayfixed = json_encode($redisarray);
$redisObj->set($key, $redisarrayfixed);
$redisObj -> close();
// If I put a line here saying 'return = $redisarrayfixed', the code runs only the first instance of the array and stops. If I omit this, it runs through all of them, but only saves the last one
}
}
redis_calendar_fetch();
As mentioned, I then use a cronjob to run this code every 30 minutes, and I have a separate piece of php code that handles the shortcode & fetches the proper saved events for the proper page.
My concern solely is with the foreach($fafull as $fa), which only saves the final result to Redis. Is there a better way to force each array instance to save?
For performance, you might want to keep just one instance of a redis connection active.
Secondly, it's only going to save the final result because on each iteration, you are using the same $key. It seems like what you want to do is iterate and push to an array, then at the end, save it entirely.
Example of how I'm understanding this;
$redisObj = new Redis();
$redisObj -> connect('localhost', 6379, 2.5, NULL, 150 );
$someArray = array();
foreach($fafull as $fa) {
$redisarrayfixed = json_encode($redisarray);
array_push($someArray, $redisarrayfixed);
}
$redisObj->set($key, $someArray);
$redisObj -> close();

Google Search Console API group results

I'm working on this project which use GSC API. Everything's working fine but I'm stuck with one kind of query : I wanna group the result by Pages so I can get all the queries (or keywords) for each page.
here's what a request looks like :
public function getTopPages($sitename){
$this->client->setAccessToken($this->getStoredToken());
$searchRequest = new \Google_Service_Webmasters_SearchAnalyticsQueryRequest;
//last month from today
$searchRequest->setStartDate($this->getDateMinusMonths("-12 months")); //'YYYY-MM-DD'
$searchRequest->setEndDate(date("Y-m-d", time()));
$dimensions = ['page', 'query'];
$searchRequest->setDimensions($dimensions);
$searchRequest->setRowLimit(10);
$searchRequest->setAggregationType('byPage');
$siteQueries = $this->webmaster->searchanalytics->query($sitename, $searchRequest);
if (count($siteQueries) > 0) {
$siteQueries = $siteQueries->getRows();
if ($siteQueries) {
return $siteQueries;
}
}
}
I tried to change the aggregationType property but it doesnt changed the result.
Here's the result
As you guys can see, there's a url coming back (url-example-1) for different keywords.
Is it possible to merge them directly from the request ? Suming all the datas (clicks, impressions, ctr...)
I know I could write a script to do it but I believe it's possible to do it natively
Thanks a lot

How to create solr document with String type using solarium query

I' creating solr document via solarium plugin in php.
But the all document is stored text_general data type except id field. text_general is the default datatype in solr system.
My doubt is why id field is only to stored string type as default.
And If any possible to add document with string type using solarium plugin.
My code part is here,
public function updateQuery() {
$update = $this->client2->createUpdate();
// create a new document for the data
$doc1 = $update->createDocument();
// $doc1->id = 123;
$doc1->name = 'value123';
$doc1->price = 364;
// and a second one
$doc2 = $update->createDocument();
// $doc2->id = 124;
$doc2->name = 'value124';
$doc2->price = 340;
// add the documents and a commit command to the update query
$update->addDocuments(array($doc1, $doc2));
$update->addCommit();
// this executes the query and returns the result
$result = $this->client2->update($update);
echo '<b>Update query executed</b><br/>';
echo 'Query status: ' . $result->getStatus(). '<br/>';
echo 'Query time: ' . $result->getQueryTime();
}
The result document for the above code is here,
{
"responseHeader":{
"status":0,
"QTime":2,
"params":{
"q":"*:*",
"_":"1562736411330"}},
"response":{"numFound":2,"start":0,"docs":[
{
"name":["value123"],
"price":[364],
"id":"873dfec0-4f9b-4d16-9579-a4d5be8fee85",
"_version_":1638647891775979520},
{
"name":["value124"],
"price":[340],
"id":"7228e92d-5ee6-4a09-bf12-78e24bdfa52a",
"_version_":1638647892102086656}]
}}
This depends on the field type defined in the schema for your Solr installation. It does not have anything to do with how you're sending data through Solarium.
In the schemaless mode, the id field is always set as a string, since a unique field can't be tokenized (well, it can, but it'll give weird, non-obvious errors).
In your case i'd suggest defining the price field as an integer/long field (if it's integers all the way) and the name field as a string field. Be aware that string fields only generate hits on exact matches, so in your case you'd have to search for value124 with exact casing to get a hit.
You can also adjust the multiValued property of the field when you define the fields explicitly. That way you get only the string back in the JSON structure instead of an array containing the string.

SOAP API / SQL Error "ORA 00904 invalid Identifier"

I have the following problem:
I need to get a few columns of a oracle db table to display information on a .php page. To do this, I'm using a SOAP-API, which works flawlessly with any other table, only not with this one.
This is the Code I am using for all of these Queries:
$setSearchObjectsIn = new SearchObjectsInType();
$setSearchObjectsIn->sessionId = (String) $sessionId;
$setSearchObjectsIn->table = (String) 'STFCFG_DD_VALUE';
$setSearchObjectsIn->caseSensitive = (String) 'false';
$setSearchObjectsIn->limitedResult = (String) 'false';
$setSearchObjectsIn->restrictions[0]['attributeName']= (String) 'STFCFG_DD_VALUE.DDID';
$setSearchObjectsIn->restrictions[0]['restriction']['operator'] = (String) '=';
$setSearchObjectsIn->restrictions[0]['restriction']['value'] = (String) $ddid;
$setSearchObjectsIn->resultColumns[0] = (String) 'STFCFG_DD_VALUE.DD_VALUE';
$setSearchObjectsIn->resultColumns[1] = (String) 'STFCFG_DD_VALUE.CATALOG_NAME';
$setSearchObjectsIn->resultColumns[2] = (String) 'STFCFG_DD_VALUE.MSG_ID';
$client = new SoapClient((String) $instance.'/axis/services/GenericApiWS?wsdl');
$result = $client->searchObjects($setSearchObjectsIn);
And this is the Error I get with this special table:
ORA-00904: "MAN_ID": ungültiger Bezeichner
I have also tried starting this query with SoapUI, which results in the exactly same thing.
The fact, that I have nothing like "MAN_ID" in my code has me wondering, as the error looks like I would query a column named like that, which I obviously don't do. (There is also no column "MAN_ID" in the requested table, so I have no idea where this comes from)
I hope you can help me
I'd try looking for MAN_ID in the SOAP server code - the error may be what the server returns and it may be looking for that column implicitly. The error message is definitely produced by Oracle, so search the way your query gets there and if possible, see what query gets executed.

Data structure to save nested XML based data

I obtain this type of response via curl:
<ArrayOfServerFile>
<ServerFile>
...
<FileType>Folder</FileType>
<Identifier>x123</Identifier>
<Name>Client Templates</Name>
...
</ServerFile>
<ServerFile>
...
<FileType>XpressDox Template</FileType>
<Identifier>y456</Identifier>
<Name>contact-information.xdtpl</Name>
...
</ServerFile>
...
</ArrayOfServerFile>
I want to save this info in a tree-like data structure.
I have tried something like this:
// Pseudo-code:
function run_procedure()
{
get XML data via curl
if FileType == 'Folder'
save name and other useful data into $tree_like_data_structure
run_procedure() // recursive call
else if FileType == 'XpressDox Template'
save name and other useful data into $tree_like_data_structure
}
var_dump($tree_like_data_structure);
The idea is to represent saved data like this:
[0][0] -> data
[1][0] -> data
[1][1] -> data
[1][2] -> [2][0] -> data
[2][1] -> data
[1][3] -> data
I am pretty sure that this is not so hard to accomplish but I have lost a lot of time without success. Any tip is very welcome. Thanks.-
EDIT 1
My main concern is how obtain [depth][element] indexes and how level data (type, name, content, etc).
EDIT 2
Basically this is a recursive programming problem. Maybe it can be done via while statements more easily than with a recursive function?
Try using SimpleXML with the DOM to create your array.
$dom = new DOMDocument;
$dom->loadXML('
<ArrayOfServerFile>
<ServerFile>
<FileType>Folder</FileType>
<Identifier>x123</Identifier>
<Name>Client Templates</Name>
</ServerFile>
</ArrayOfServerFile>');
if (!$dom) {
echo 'Error while parsing the document';
exit;
}
$s = simplexml_import_dom($dom);
echo $s->ServerFile[0]->FileType;

Categories