outputs it in the structured data format required by Google for reviews

PHP code that creates a form to capture review data and outputs it in the structured data format required by Google for reviews:

// Set up variables to store form data
$name = $rating = $review = '';

// Check if form is submitted
  // Sanitize input data
  $organname = htmlspecialchars($_POST['organname']);
  $subjectname = htmlspecialchars($_POST['subjectname']);
  $name = htmlspecialchars($_POST['name']);
  $reviewpost = htmlspecialchars($_POST['reviewpost']);

  // Output structured data for review
$review_data = array(
  '@context' => 'http://schema.org/',
  '@type' => 'Review',
  'itemReviewed'  => array(
    '@type' => 'Organization',
    'name'=> $organname,
  'reviewRating' => array(
    '@type'=> 'Rating',
    'ratingValue' => '5',
    'bestRating' => '5'
  'name'=> $subjectname,
  'author'=> array(
    '@type'=> 'Person',
    'name'=> $name,
  'reviewBody'=> $reviewpost,

  $json_ld = json_encode($review_data);
  $newreview = '<script type="application/ld+json">'.$json_ld.'</script>';

  // Save form data to file
  $file = fopen('reviews.txt', 'a');
  fwrite($file, "$newreview\n\n");

  // Clear form data
  $name = $rating = $review = '';

<!-- HTML form for review data -->
<form method="post">
  <label for="organname">Organization Name:</label>
  <input type="text" name="organname" value="<?php echo $organname; ?>"><br>

  <label for="subjectname">Subject Name:</label>
  <input type="text" name="subjectname" value="<?php echo $subjectname; ?>"><br>

  <label for="name">Name:</label>
  <input type="text" name="name" value="<?php echo $name; ?>"><br>

  <label for="reviewpost">Review Post:</label>
  <textarea name="reviewpost"><?php echo $reviewpost; ?></textarea><br>

  <input type="submit" value="Submit">

This code creates a form with three input fields for the name, rating, and review text. When the form is submitted, the input data is sanitized and used to create a JSON-LD object with the structured data for the review. The JSON-LD object is then output in the script tag, which Google can read and use to display the review in the search results.

Related Articles

- All From ChatGPT