简体   繁体   English

使用php代码在twitter tweet时间轴中图像和文本未正确对齐

[英]image and text not aligning properly in twitter tweet timeline using php code

am trying to retrieve the timeline of my twitter home page using php code .when i try to reproduce the timeline the profile pic and tweet text is not aligned properly. 我试图使用php代码检索我的Twitter主页的时间轴。当我尝试重现时间轴时,个人资料图片和tweet文本未正确对齐。 when i use float left in the image tag some of the tweets are aligned properly but some of them are misaligned.i am unable to attach the screenshot.i dont want to use javascript.can someone let me know what mistake am making. 当我在图片标签中使用float时,某些推文已正确对齐,但其中一些未对齐。我无法附加屏幕截图。我不想使用javascript。有人可以让我知道发生了什么错误。 i want the profile pic and tweet text side by side. 我想要个人资料图片和推文并排。 html code: html代码:

<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">

</head>
<body>
<?php
require_once('TwitterAPIExchange.php');
/** Set access tokens here - see: https://dev.twitter.com/apps/ **/
$settings = array(
    'oauth_access_token' => "",
    'oauth_access_token_secret' => "",
    'consumer_key' => "",
    'consumer_secret' => ""
);
$url = "https://api.twitter.com/1.1/statuses/home_timeline.json";
$requestMethod = "GET";
if (isset($_GET['user'])) {$user = $_GET['user'];} else {$user = "srini001";}
if (isset($_GET['count'])) {$count = $_GET['count'];} else {$count = 20;}
$getfield = "?screen_name=$user&count=$count";
$twitter = new TwitterAPIExchange($settings);
$string = json_decode($twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest(),$assoc = TRUE);

$user_timeurl = "https://api.twitter.com/1.1/statuses/user_timeline.json";
$user_timestring = json_decode($twitter->setGetfield($getfield)
->buildOauth($user_timeurl, $requestMethod)
->performRequest(),$assoc = TRUE);


if($string["errors"][0]["message"] != "") {echo "<h3>Sorry, there was a problem.</h3><p>Twitter returned the following error message:</p><p><em>".$string[errors][0]["message"]."</em></p>";exit();}
$x = 1;

echo"test";echo "<br />";
$twet="RT @MercedesAMGF1: Good to see @SChecoPerez and @NicoHulkenberg back in business today. Top work from @ForceIndiaF1 :) #MBFamily #F1";
echo "$twet";echo "<br />";
        $txt = preg_replace('/@(\S+)/i', '<a href="https://twitter.com/#!/$1">@$1</a>', $twet);

echo "$txt";echo "<br />";

foreach($string as $items)
    {
        echo "text";"<br/>";
        $tw = $items['text'];



        echo "$x"; echo "<br />";
        echo "Time and Date of Tweet: ".$items['created_at']."<br />";
        echo "Tweeted by: ". $items['user']['name']."<br />";
        echo "Screen name: ". $items['user']['screen_name']."<br />";
        echo "Followers: ". $items['user']['followers_count']."<br />";
        echo "Friends: ". $items['user']['friends_count']."<br />";
        echo "Listed: ". $items['user']['listed_count']."<br /><hr />";
        $x=$x +1;
    }
?>
<div class="blok">
    <h1>html</h1>
    <?php
    foreach($string as $items)
    {
                $tw = $items['text'];
                $screen_name = $items['user']['screen_name'];
                $prof_img = $items['user']['profile_image_url'];
                $txt = preg_replace('/http:\/\/(\S+)/i', '<a href="http://$1">http://$1</a>', $tw);
                $txt = preg_replace('/https:\/\/(\S+)/i', '<a href="http://$1">https://$1</a>', $txt);

                $txt = preg_replace('/#(\S+)/i', '<a href="https://twitter.com/#!/#$1">#$1</a>', $txt);
                                //echo "$txt"; echo "<br />";

                $txt = preg_replace('/@(\S+)/i', '<a href="https://twitter.com/#!/$1">@$1</a>', $txt);


                ?>
                <div ><img style="float:left"  src = "<?= $prof_img ?> "/><?= $txt ?></div>
                <br/>

<?

    }
?>
</div>

<div class="blok">
    htmltest

</div>
</body>
</html>

my css code: 我的CSS代码:

.blok{
    display: inline-block;
  font-family: "Helvetica Neue", Roboto, "Segoe UI", Calibri, sans-serif;
  font-size: 12px;
  font-weight: bold;
  line-height: 16px;
  border-color: #eee #ddd #bbb;
  border-radius: 5px;
  border-style: solid;
  border-width: 1px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
  margin: 10px 5px;
  padding: 0 16px 16px 16px;
  max-width: 468px;
  max-height: 400px;
  overflow-y: auto;
}

.blok p {
  font-size: 16px;
  font-weight: normal;
  line-height: 20px;
}

.blok a {
  color: blue;
  font-weight: normal;
  text-decoration: none;
  outline: 0 none;
}

.blok a:hover,
blockquote.twitter-tweet a:focus {
  text-decoration: underline;
}

i updated the css to below: 我将CSS更新为以下内容:

.line{    
    height: 60px;
    margin-left:65px;

  }

  .twprof{
    height: 60px;
    float: left;

  }

also i updated the html code to below: 我也将html代码更新如下:

<div class="twprof" ><img src = "<?= $prof_img ?> "/></div><div class="line" ><b><?= $screen_name ?> : </b><?= $txt ?></div>

it works fine now. 现在工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM