Save items from array on mysql with php

370

Hi i have one situation and i dont know what exactly i need to do.

This is a multiple file upload so im doing this

$files = $_POST["files-temp"];

this return ( iten1.jpg;iten2.jpg;iten3.jpg;) there is a semicolon on last iten

then i did

$array = preg_split('/;/',$files);

then i got

Array ( [0] => iten1.jpg [1] => iten2.jpg [2] => iten3.jpg [3] => )

So there is a iten 4 that not exists, so i need to find a better way to do this then count and execut the query to save on mysql.

thanks for any help.

350

Answer

Solution:

If$files contains a string and want to remove that last extra array location:

Try:

$files = 'iten1.jpg;iten2.jpg;iten3.jpg;';
$result = explode(";", rtrim($files,';'));
print_r( $result );

Test Here

People are also looking for solutions to the problem: php - Using file_get_contents() / cURL or API to get financial data?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.