Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

needHelp's avatar

How to convert raw PHP to laravel?

i need some help on how to convert a raw php code to laravel.

$word = ['0' => 'how', '1' => 'you']; $output = array(); $word = mysqli_real_escape_string($mysqli, $word); $words = mysqli_query($mysqli, "SELECT word FROM dictionary WHERE SUBSTRING(word, 1, 1) ='".mysqli_real_escape_string($mysqli, substr($word, 0, 1))."' "); while(($words_row = mysqli_fetch_assoc($words)) !== false && in_array($word, $words_row) == false){ similar_text($word, $words_row['word'], $percent); if($percent >= 75){ $output[] = $words_row['word']; } if($words_row['word'] == null){ break; } }

0 likes
2 replies
danmatthews's avatar

Hey there.

Check out the query builder documentation:

https://laravel.com/docs/5.4/queries

All your WHEREs become either ->where() or ->whereRaw() calls, and you don't have to use mysqli_real_escape_string as the query builder will handle all of that for you.

Please or to participate in this conversation.