Jump to content

Code critique


leke

Recommended Posts

Hi, I hope this is still a relevant topic here. I don't have a lot of coding experience and haven't studied it a college -- I'm just self taught hobbyist. I was wondering what your opinion is of the way I have structured my code and solved what I needed to do.

 

Any tips or feedback is greatly appreciated. Thanks.

 

<?php
$form_submission=$_POST["query"];
$lines = file('eo_dic.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); 
preg_match_all('/[\w\'\ŝ\ĉ\ĵ\ŭ\ĥ\Ŝ\Ĉ\Ĵ\Ŭ\Ĥ]+|[,.;!"?-\s\\(\\)]/', $form_submission, $matches);

foreach ($matches[0] as $value){ 
  // Check if $value is a word or something else.
  if ($value == " " || $value == "," || $value == "." || $value == "(" || $value ==  ")" || $value == "!" || $value == "?" || $value == "-" || $value == ";" || $value == '"'){
    echo $value;
  }
  else { // $value is a word.
    $titleText = array(); // store results in array.
    foreach ($lines as $line){
      list($field1, $field2) = explode('=', $line);
      if (strcasecmp($field1, $value) == 0 || strcasecmp($field2, $value) == 0){ // Found string in DB.
        array_push($titleText, "$field1 = $field2"); // Store all finds in array before outputting.
      }
    }
    if (empty($titleText)) { // $value was not found -- array is empty.
      echo '<a name="translated" class="translated" title="Not found.">' . $value . '</a>';
    }
    else {
      $arrayOut = implode(" / ", $titleText); // output the results found in the search.
      echo '<a name="translated" class="translated" title="' . $arrayOut . '">' . $value . '</a>';
    }
  }
}
unset($value);
?>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.