Read .ddd file with PHP

I would like to read a .ddd (digital tachograph) file (into an array,xml,json,whatever) with PHP. Has anyone done something similar? Where should I start?

I found only C# solution but it is not suitable

Not unique table/alias: ‘quiz_table’

I’ve created a web app using code igniter 3 to get data from 3 tables and display them in the view (quiz_table,question_table and answers_table).
Below is the model code,

function getSingleQuizQuestionDataFromDB($quizId)
{        //insert query
    try {
        $this->db->select('quiz_table.quizName');
        $this->db->select('quiz_table.creatorName');
        $this->db->select('quiz_table.rating');
        $this->db->select('question_table.questionId');
        $this->db->select('question_table.questionTitle');
        $this->db->select('question_table.correctAnswer');
        $this->db->select('answer_table.answer');
        $this->db->from('quiz_table');
        $this->db->where('quiz_table.quizId',$quizId);
        $this->db->join('question_table','question_table.quizId = quiz_table.quizId','INNER');
        $this->db->join('answer_table','answer_table.questionId= question_table.questionId','INNER');
        $this->db->from('quiz_table');
        $this->db->group_by(['quiz_table.quizId', 'question_table.questionId']);
        $result = $this->db->get();


        $singleQuizQuestionData= $result->result_array();
        return $singleQuizQuestionData;
    } catch (Exception $e) {
        // log_message('error: ',$e->getMessage());
        return;
    }
}

When I try to load the result I get the below error
enter image description here

Please help!

How to hide manager password from user on web app?

I am creating a web app on a LAMP stack where I have users with their own logins and passwords. Typical users of the application have limits on operations. For example they cannot approve an order over $5000. If there is an order over $5000, they have to get a manager to come to their desk and enter in his/her username and password to approve the order.

I can easily create a form for the manager to enter his/her credentials into an HTML password input, but here is the problem. When the manager enters their credentials into the browser, the password field is hidden from the user. But when the form is submitted, the password is transmitted in clear text. In theory, a user could get the password by using F12 or by looking at the POST.

I wanted to hash the passwords before submitting the form, but the problem is that PHP stores the passwords using BCRYPT, and javascript can only digest with SHA.

So basically my question is. How can I ensure that the manager password is hidden from the user and they cannot get it?

Convert simple text with titles and subtiles into h2 and h3 respectively

I am using an Open API to fetch list of titles or articles in my php/wordpress script. The format in which the API sends the response is like this :

Titles
1. The Versatile Vehicle: Driving with Style
2. Upgrade Your Ride: Discover the Thrills of Automobile Innovation
3. For Travellers and Adventurers: Exploring the Best in Automotive Design
4. Safety on the Road: Navigating with the Latest in Car Technology
5. The Lure of Luxury: Enjoying the Finest in Automotive Comfort

Subtitles
1. Expanding

So from the above response I want the Titles to be converted to h2 tags automatically and the Subtitles to h3. So it would be like this:

<h2>The Versatile Vehicle: Driving with Style</h2>

<h3>Expanding</h3>

So far I have tried this:

$ps = preg_split('#<p([^>])*>#',$txt);

This to convert p tags to array.

if (str_contains($ps[1], "Titles")) 
                    {
                        $titles = $ps[2];
                    }

This to check if string contains Titles than store that string in array after that seperated text using <br> tag.

$titles_array = preg_split('#<br([^>])*>#',$titles);

But this doesn’t seem to work. I am looking for a simple php or javascript solution. Thanks in advance.

Why am I getting unassigned variable errors in Laravel vendor folder when using VSCode?

I’ve tried to clone a Laravel project from my Docker-Laravel repository. After installing the composer the vendor folder is added with a red color, and I’m getting errors like the below images in files inside the vendor:

enter image description here

I think this is because of the PHP configuration but I don’t know how to fix this. everything is alright in PHPStorm.
The installed PHP address is /opt/homebrew/opt/[email protected]/bin/php and I’ve added this address to setting.json file of VSCode with "php.executablePath": "/opt/homebrew/opt/[email protected]/bin/php" code

Also I’ve added the export PATH="/opt/homebrew/opt/[email protected]/bin:$PATH" to the ~/.zshrc file.
This doesn’t pause my work but it’s annoying to see these red alerts. How can I solve this?

htmlspecialchars not allowing url to open

Am using

<form action="<?php echo htmlspecialchars(Uri::getInstance()->toString()); ?>" method="post"
      name="adminForm" id="adminForm">

However, theres dynamic link which is generated like on clicking link as

https://www.mywebsite.com/index.php?option=com_rsform&formId=1&form[car]=Honda&form[Model]=City%20Hybrid%20e%20HEV

Due to above code for htmlspecialchars link on clicking is just refresing the page. I understand the purpose of htmlspecialchars for security

Any workaround solution that the dynamic link as generated can be executed.

SQL Query Phpmyadmin is not giving correct results having more than 3 tables with WHERE Clause

I am having relational database and trying to execute following query up to 3 tables It is giving me correct results i.e. 248 records of students in institute id 910, but when I try to make a query having more than 3 tables it gives me 19000+ results.

SELECT * 
FROM Student,StudentRegistration,RefStudentType,RefGender,SubjectCategory 
WHERE Student.student_id=StudentRegistration.student_student_id 
AND StudentRegistration.reg_student_type_std_type_id = RefStudentType.std_type_id 
AND Student.student_gender_gender_id = RefGender.gender_id 
AND StudentRegistration.reg_student_subjectCat_sub_cat_id=SubjectCategory.sub_cat_id 
AND Student.student_institute_inst_id=910;

Any solution, query logical errors or something new

Speed up curl response in php

I am using curl to connect to online Business Central (BC) web API, via OData. On postman, it takes a max of 1.9 seconds, but takes between 40 to 90 seconds on local server.
Any idea on how I can best improve this?

Here’s a sample of one of my curls – I have placed them in classes and passing the link, access token, and post fields (for POST to BC tables) via the class methods.

`

<?php
    class employeeData
    {
      public function employee_meta_data($url,$access_token){
        $curl = curl_init();

        curl_setopt_array($curl, array(
          CURLOPT_URL => $url, 
          CURLOPT_RETURNTRANSFER => true,
          CURLOPT_ENCODING => '',
          CURLOPT_MAXREDIRS => 10,
          CURLOPT_TIMEOUT => 0,
          CURLOPT_FOLLOWLOCATION => true,
          CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_2TLS,
          CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4,
          CURLOPT_SSL_VERIFYPEER => false, //disable SSL certificate verification
          CURLOPT_CUSTOMREQUEST => 'GET',
          CURLOPT_HTTPHEADER => array(
            'Authorization: Bearer '.$access_token.'',
            'Connection: keep-alive'
          ),
        ));
  
        $response = curl_exec($curl);
        
       if($response == FALSE) 
        {
           //die("Web API Failed: ".curl_error($curl));
        }else
        {
          $response_http_code  = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);

          curl_close($curl);
                
       if($response_http_code >= 200 && $response_http_code <= 202){
         $msg = json_decode($response);
      }else
          {
         $msg = "error";
          }
          
          return $msg;
         
    }
      }
   }

   $employeeMetaData = new employeeData();
?>

I have gone through the previous recommended answers on this and other platforms, such as changing the http version to CURL_HTTP_VERSION_2TLS. Also, CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4 seems to work miracles for others but fails on to do the same on my side. Encoding is also enabled, but no changes still.
My internet speed (both home wifi and for the organisation) is fast and stable

How can I make this javascript code to php? [closed]

int key = 6;
       String text ="Hellow Word!";
        char [] chars = 
        text.toCharArray();
        System.out.println(text);
        for (char c : chars){
            c += key;
            System.out.print(c);
        }
Sample output:

Hellow Word!

Nkrru}&]uxj

I tried to convert this code to a php one but i find it very hard.

How would I sort database results by new – old [closed]

I am working on a project and I get results from a mysql database.

<?php
$servername = "hostname";
$username = "username";
$password = "pw";
$dbname = "app";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
  die("Connection failed: " . mysqli_connect_error());
}

$sql = "SELECT email, title, location, description, date FROM food";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
  // output data of each row
  while($row = mysqli_fetch_assoc($result)) {
    echo "email: " . $row["email"]. " - title: " . $row["title"]. " - location: " . $row["location"].  "<br>";
    echo "" . $row["description"]. " - date: " . $row["date"]. "<br> <br> <br>";
  }
} else {
  echo "0 results";
}

mysqli_close($conn);
?>

When I do this it works but it sorts the results old – new.

How would I be able to “reverse” this list

I tried to use ORDER BY date_added but it just gave me an error.

Laravel 8 Exception handler for ThrottleRequestsExcception doesn’t return json

I’ve migrated my Laravel 5.7 project to 8 and have an API endpoint called optouts which has a throttle on it. When I make post requests to this endpoint in quick succession, I should be given a JSON response rather than the HTML variant of the page. I’ve migrated over to the register and reportable method, here’s my PHP code:

<?php

namespace AppExceptions;

use IlluminateFoundationExceptionsHandler as ExceptionHandler;
use IlluminateHttpExceptionsThrottleRequestsException;
use Throwable;

class Handler extends ExceptionHandler
{
    /**
     * A list of the exception types that are not reported.
     *
     * @var array
     */
    protected $dontReport = [
        //
    ];

    /**
     * A list of the inputs that are never flashed for validation exceptions.
     *
     * @var array
     */
    protected $dontFlash = [
        'current_password',
        'password',
        'password_confirmation',
    ];

    /**
     * Register the exception handling callbacks for the application.
     *
     * @return void
     */
    public function register()
    {
        $this->reportable(function (ThrottleRequestsException $e, $request) {
            if ($request->is('api/*')) {
                return response()->json([
                    'message' => 'Too many requests.'
                ], 429);
            }
        });
    }
}

But when I make requests to my endpoint I’m still given the HTML variant, not the JSON page. What am I missing here?

array_combine() not giving the expected result in php

I have two arrays as follows, Array a represents the quntites while array b stores the product names

Array A

array:9 [▼
  0 => 2
  1 => 3
  2 => 10
  3 => 3
  4 => 4
  5 => 8
  6 => 5
  7 => 1
  8 => 1
]

Array B

array:9 [▼
  0 => "Hello world poduct"
  1 => "Test Product"
  2 => "Hello world poduct"
  3 => "Hello world poduct"
  4 => "Test Product"
  5 => "Test Product"
  6 => "Test Product"
  7 => "Test Product"
  8 => "Test Product"
]

Now I’m trying to combine these two arrays and get the following output,

Array 
  ( 
       [Hello world poduct] => 2
       [Test Product]       => 3 
       [Hello world poduct] => 10
       [Hello world poduct] => 3
       [Test Product]       => 4 
       [Test Product]       => 8 
       [Test Product]       => 5 
       [Test Product]       => 1 
       [Test Product]       => 1 
)

I tried using PHP’s array_combine() function

array_combine($arr_a,$arr_b)

This is not giving me the expected output…What changes should I make in order to take the expected result…or what would be the correct approach creating new array with expected way…

UPDATE

My final goal is to take the products and their total as mentioned bellow,

Array(
  [Test Product] => 22 
  [Hello world poduct] => 15 
)

As @foobar mentioned in the comments, since my keys are not unique, what coould be the better way doing this?

getting duplicating records in my inner and left join Query in PHP

I want to get categories and its forms and also user’s form which he selected but my query getting double record for those forms which user selected. my query is this.

   SELECT forms.* , cat.category_title,cat.type,ufrm.formID FROM tbl_tax_forms as forms 
   INNER JOIN tbl_form_categories as cat ON cat.id= forms.cat_id 
   LEFT JOIN tbl_client_forms as ufrm ON ufrm.formID=forms.id 
   WHERE forms.cat_id =1 order by forms.cat_id ASC,forms.id ASC

my Result is as follow

   form_title                 category_title       type formID
    Single                    Individual Tax Return 1    1
    Single                    Individual Tax Return 1    1
    Married Filing Separately Individual Tax Return 1   NULL 
    Married Filing Jointly    Individual Tax Return 1   NULL

user selected formID 1 with title Single so this is repeating twice. this should be also display one record.
Please help with thanks

Show surname and rest of the name

I have a database with customer names, and I want to separate the last name from the rest of the name.

In the name Diana Margarida Paulino Maria

If I use:

$str = "Diana Margarida Paulino Maria";

// Get Frist and Last Word
   $array = explode(" ",$str);

   $first_word = $array[0];

   $last_word  = $array[count($array)-1];

   echo $first_word. ', '.$last_word;

It’s every thin ok, anda show Diana as first_word and Maria as last_word

Even is I use:

    function getLastWord($string)
    {
        $string = explode(' ', $string);
        $last_word = array_pop($string);
        return $last_word;
    }

Or this

  $words = explode( " ", $str );
array_splice( $words, -1 );
echo implode( " ", $words );

In this case show name without surname

The problem is that if you return a php msqyl select query from that name and use these functions, the nickname never appears

I’ve tried directly through the mysql query itself

SELECT substring_index(nome, ' ', 1) as first, substring_index(nome, ' ', -1) as last

And in the specific case of this name (and some others – Leandro Monteiro Rodrigues Figueiredo; Pedro António Duarte Lopes) the nickname still does not appear

I used the above codes with many other names and in almost all situations the nickname is indicated correctly

In the mysql database the name field is encoded with utf8_general_ci

Either way it’s weird because I can’t find a pattern for the error