Php 有可能在数组值内有EOT吗?

Php 有可能在数组值内有EOT吗?,php,Php,呃,为什么这行不通呢; 一般来说,我遇到的问题是字符串中有单引号和双引号 <?php use Illuminate\Database\Seeder; use Illuminate\Database\Eloquent\Model; use App\Models\StaticPage; class StaticPageTableSeeder extends Seeder { /** * Run the database seeds. * * @ret

呃,为什么这行不通呢;

一般来说,我遇到的问题是字符串中有单引号和双引号

<?php

use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
use App\Models\StaticPage;

class StaticPageTableSeeder extends Seeder
{

    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run() {

        Model::unguard();

        DB::table('static_pages')->truncate();

        StaticPage::create([

            'slug'           => 'car-loans';
            'titles_en'      => '<h1>Car Loan</h1><h2>What you need to get one</h2>';
            'featured_image' => 'article_uploads/text-page-bgr.jpeg';
            'content_en'     => 

<<<EOT

                        <p class="highlight">The vast majority of cars aren't bought by consumers at all; they're purchased by banks. Very few buyers pay cash outright. The rest either borrow or lease a car from the real owner: a bank, an automaker's finance arm or a credit union. Shopping for a loan isn't as fun as shopping for the car itself, but it's not as difficult as securing a mortgage, either. We recommend that you shop around for a loan before you go to a dealership. Before you can shop for a loan, though, you'll need to determine a few things.</p>
                        <h3>Determine What Car You Can Afford</h3>
                        <p>It might seem difficult to make this determination before test-driving a bunch of cars, but it's best to steer clear of the sales floor until you've done your research. <q class="hidden-sm hidden-xs">The vast majority of cars aren't bought by consumers at all; they're purchased by banks.</q> Affordability isn't just about the car's price; it's about the cost of financing, insuring, fueling and maintaining it. If you're like most shoppers, you have an idea of the type you want and how much car you're likely to get for the amount you've got to spend. Be sure to include one-time charges like taxes, title and license fees, and the destination charge when you're figuring out how much you can spend, as well as factoring in continuing costs such as insurance and gas.</p>
                        <h3>Shop for Loans Before Going to the Dealership</h3>
                        <p>If you're buying a new car, the financing with the best interest rate might come from the automaker, available only through the dealer. Zero percent financing and other seemingly too-good-to-be-true offers come from so-called "captive" finance companies like GM's GMAC and Toyota Financial Services. Often they're not too good to be true (though the best terms are limited to specific models, loan periods and buyers with the best credit ratings). Dealers don't always have the best deals, though, and when they're not operating through a captive finance company they get a commission for setting up a loan with a bank you could go to directly.</p>
                        <figure class="__img-caption">
                            <img src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9InllcyI/PjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB3aWR0aD0iNjAwIiBoZWlnaHQ9IjQwMCIgdmlld0JveD0iMCAwIDYwMCA0MDAiIHByZXNlcnZlQXNwZWN0UmF0aW89Im5vbmUiPjwhLS0KU291cmNlIFVSTDogaG9sZGVyLmpzLzYwMHg0MDAvYXV0bwpDcmVhdGVkIHdpdGggSG9sZGVyLmpzIDIuNS4wLgpMZWFybiBtb3JlIGF0IGh0dHA6Ly9ob2xkZXJqcy5jb20KKGMpIDIwMTItMjAxNSBJdmFuIE1hbG9waW5za3kgLSBodHRwOi8vaW1za3kuY28KLS0+PGRlZnMvPjxyZWN0IHdpZHRoPSI2MDAiIGhlaWdodD0iNDAwIiBmaWxsPSIjRUVFRUVFIi8+PGc+PHRleHQgeD0iMjI1LjEzMjgxMjUiIHk9IjIwMCIgc3R5bGU9ImZpbGw6I0FBQUFBQTtmb250LXdlaWdodDpib2xkO2ZvbnQtZmFtaWx5OkFyaWFsLCBIZWx2ZXRpY2EsIE9wZW4gU2Fucywgc2Fucy1zZXJpZiwgbW9ub3NwYWNlO2ZvbnQtc2l6ZTozMHB0O2RvbWluYW50LWJhc2VsaW5lOmNlbnRyYWwiPjYwMHg0MDA8L3RleHQ+PC9nPjwvc3ZnPg==" data-src="holder.js/600x400/auto" alt="600x400" data-holder-rendered="true">
                            <figcaption class="__caption hidden-sm hidden-xs">
                                Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut...
                            </figcaption>
                        </figure>
                        <p>After you've negotiated the car's purchase price, the only way to know if the deal you're presented with is a good one is for you to have shopped around beforehand. You may not be able to shop rates from the captive lenders before actually buying a car, but you can find out what kind of rates are available at banks and credit unions.</p>
                        <p>To know what kind of rate to expect, and to head off any obstacles you may encounter, you'll need to know your credit rating. Any lender will look it up as soon as you sit down with them to negotiate a loan. The rating takes into account how long you've had credit, how diligently you pay bills, how much of your available credit you've used, and your mix of revolving credit — such as credit cards — and more desirable debt, like a mortgage and previous car loans.</p>

EOT;

        ]);


    }
}

这当然可以在其他命令中使用“herdeoc”字符串定义。您必须使用正确的语法:

<?php

$catalog = [
  'A' => 'thing A',
  'B' => 'thing B',
  'C' => <<<EOT
this is thing C
it has a bright color
it feels warm and smooth
EOT
];

print_r($catalog);

注意:在结束
EOT
之后不能有分号(
),因为这将终止命令。这在数组声明中没有意义

这叫一个。“EOT”文本是任意的。处理混合包含的单引号和双引号的另一种方法是通过在它们前面加反斜杠(``)来转义它们以强制它们的字面意义。通过这种方式,您可以定义包含用作字符串分隔符的字符的字符串:@arkascha有时不可行,因为您必须手动插入大量字符。您可以为自己制作一个简单的脚本来完成这项工作。有些IDE甚至集成了这样的功能。但我同意,有时,herdoc和nowdoc字符串定义的替代方法会派上用场。特别是为了提高代码的可读性。
Array
(
    [A] => thing A
    [B] => thing B
    [C] => this is thing C
it has a bright color
it feels warm and smooth
)