user3544484
user3544484

Reputation: 851

Remove part of url link being created by variable

I have a link that is created by a variable as below:

<div class="pdf-download">
   <a href="/images/documents/187/pdf-test.pdf|Download">Download</a>
</div>

This is being created by the following:

<div class="pdf-download">
   <a href="/images/documents/<?= $this->item->id; ?>/<?= $pdfdownload ?>">Download</a>
</div>

I need to remove the "Download" from the url that is created by $pdfdownload.

What is the best way to do this?

Upvotes: 0

Views: 94

Answers (2)

PopTheStack
PopTheStack

Reputation: 11

If the |Download is always at the end,
you can replace $pdfdownload with preg_replace('/pdfdownload\|$/','',$pdfdownload)

Upvotes: 1

Perfect28
Perfect28

Reputation: 11317

You can just replace '|Download' with an empty string with str_replace.

 <a href="/images/documents/<?= $this->item->id; ?>/<?= str_replace('|Download', '', $pdfdownload) ?>">Download</a>

Upvotes: 2

Related Questions