如何在php中连接包含()的变量和字符串

时间:2017-03-14 07:32:41

标签: php string-concatenation

我想输出字符串:

Mango Meals (April Song)

但是我收到了字符串:

"Mango Meals (April Song)"

如何正确连接php中的字符串和变量?

HTML

$title = $row[ 'title'];
$credit = $row[ 'credit' ];
print('<div class = "album_title"> "'.$title.' ('.$credit.')" </div>');

4 个答案:

答案 0 :(得分:0)

您只需要删除字符串中的引号。

print('<div class = "album_title">'.$title.' ('.$credit.')</div>');
//                              --^--                   --^--

答案 1 :(得分:0)

使用sprintf

echo sprintf('<div class = "album_title"> %s (%s)" </div>', $title, $credit);

这比转义引号或连接字符串更简单。

答案 2 :(得分:0)

像这样改变

 ApiInterface apiInterface = ApiClient.getRetrofit().create(ApiInterface.class);
    Call<People> call = apiInterface.getPeopleDetails(personId,getResources().getString(R.string.api_key));
    call.enqueue(new Callback<People>() {
        @Override
        public void onResponse(Call<People> call, Response<People> response) {

            People peopleResponse = response.body();

            v.biography.setText(peopleResponse.getBiography());
            v.dob.setText(String.valueOf(peopleResponse.getBirthday()));

            v.gender.setText(String.valueOf(peopleResponse.getGender()));

            v.homepage.setText(String.valueOf(peopleResponse.getHomepage()));
            v.imdbid.setText(peopleResponse.getImdbId());
            v.popularity.setText(String.valueOf(peopleResponse.getPopularity()));
            v.place_of_birth.setText(peopleResponse.getPlaceOfBirth());
            Picasso.with(getApplicationContext()).load("http://image.tmdb.org/t/p/w185"+peopleResponse.getProfilePath()).resize(150,220).into(v.personImageView);

        }

        @Override
        public void onFailure(Call<People> call, Throwable t) {

            t.printStackTrace();
        }
    });

答案 3 :(得分:0)

你在(html文本)字符串中有双引号 试试没有它

print('<div class = "album_title"> '.$title.' ('.$credit.') </div>'); 
相关问题