2

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.

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Welcome to Stackoverflow. If it is working for you, you can accept this answer.
by the away the best method now for save on mysql is usign foreach, like foreach( $result as $key => $val ) { $query=......}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.