Avatar billede YoJonas Nybegynder
27. marts 2014 - 09:53 Der er 4 kommentarer

Limit character i echo

Jeg er ikke den store haj til PHP og har derfor et lille spørgsmål. Kort og godt så skal jeg have sat et limit af characters på eksempelvis 100 på min PHP-kode:

<?php echo $this->description; ?>

Nogen som kan hjælpe med at skrive koden? :)
Avatar billede michael_stim Ekspert
27. marts 2014 - 09:56 #1
Den lette:

<?php echo substr($this->description, 0, 100); ?>
Avatar billede YoJonas Nybegynder
27. marts 2014 - 10:56 #2
Hmm, den giver mig en fejl når jeg skriver det ind. Min kode ser sådan her ud:

<!-- indexer::stop -->
<div class="<?php echo $this->class; ?> block"<?php echo $this->cssID; ?><?php if ($this->style): ?> style="<?php echo $this->style; ?>"<?php endif; ?>>

  <?php if ($this->headline): ?>
    <<?php echo $this->hl; ?>><?php echo $this->headline; ?></<?php echo $this->hl; ?>>
  <?php endif; ?>

  <div class="rss_default_header">
    <h1><a href="<?php echo $this->link; ?>" target="_blank"><?php echo $this->title; ?></a></h1>
    <?php if ($this->image): ?>
      <a href="<?php echo $this->href; ?>" title="<?php echo $this->alt; ?>"><img src="<?php echo $this->src; ?>" alt="<?php echo $this->alt; ?>"></a>
    <?php endif; ?>
    <?php if ($this->description): ?>
      <div class="description"><?php echo $this->description; ?></div>
    <?php endif; ?>
  </div>

  <?php foreach ($this->items as $item): ?>
    <div class="rss_default<?php echo $item['class']; ?>">
      <h2><a href="<?php echo $item['link']; ?>" target="_blank"><?php echo $item['title']; ?></a></h2>
      <div class="description"><?php echo $item['description']; ?></div>
    </div>
  <?php endforeach; ?>

  <?php echo $this->pagination; ?>

</div>
<!-- indexer::continue -->
Avatar billede YoJonas Nybegynder
27. marts 2014 - 10:56 #3
Selvfølgelig uden, at koden er lavet om.
Avatar billede YoJonas Nybegynder
27. marts 2014 - 18:54 #4
Når jeg skriver det ind sådan her sker der ikke en fløjtende fis:

<!-- indexer::stop -->
<div class="<?php echo $this->class; ?> block"<?php echo $this->cssID; ?><?php if ($this->style): ?> style="<?php echo $this->style; ?>"<?php endif; ?>>

  <?php if ($this->headline): ?>
    <<?php echo $this->hl; ?>><?php echo $this->headline; ?></<?php echo $this->hl; ?>>
  <?php endif; ?>

  <div class="rss_default_header">
    <h1><a href="<?php echo $this->link; ?>" target="_blank"><?php echo $this->title; ?></a></h1>
    <?php if ($this->image): ?>
      <a href="<?php echo $this->href; ?>" title="<?php echo $this->alt; ?>"><img src="<?php echo $this->src; ?>" alt="<?php echo $this->alt; ?>"></a>
    <?php endif; ?>
    <?php if ($this->description): ?>
      <div class="description"><?php echo substr($this->description, 0, 100); ?></div>
    <?php endif; ?>
  </div>

  <?php foreach ($this->items as $item): ?>
    <div class="rss_default<?php echo $item['class']; ?>">
      <h2><a href="<?php echo $item['link']; ?>" target="_blank"><?php echo $item['title']; ?></a></h2>
      <div class="description"><?php echo $item['description']; ?></div>
    </div>
  <?php endforeach; ?>

  <?php echo $this->pagination; ?>

</div>
<!-- indexer::continue -->
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester