This topic is locked

including " within a string in calculated field

4/14/2020 2:58:36 PM
PHPRunner General questions
N
nagate816 authorDevClub member

Hi,
I'm sure this is a simple one. I want to create a clickable link to open a website in a new window from a field:
the formula I have in the "View As" is:
if (strlen($value) > 0)

$value = "<a href='http://".$value."target=\"_blank\">".$value."</a>";;

else

$value="";
I tried to use \ before the " for the "_blank" portion but that doesn't work.
Does anyone know what to use to designate that the " is within the text not the text identifier ?
Thanks.
Neil.

S
salus1DevClub member 4/14/2020

No t sure if this would cause the problem but would a single quote mark in front of http require a closing single quote mark after _blank\"?
$value = "<a href='http://".$value."target=\"_blank\">".$value."</a>";;

N
Nir Frumer 4/14/2020

hi

you may also consider trim($value) in the 1st value
hope it helps,

Sergey Kornilov admin 4/15/2020

Guys, learn how to use code formatting in this forum, makes the code easier to read and understand and also will help to spot mistakes.
Second, instead of saying > that doesn't work

say something about what exactly is happening. Like link won't open at all or will open in the same window etc.
In PHP you mix single and double quotes, can be easier than adding \ in front of each double quote. This is what I think will work. The single quote after the URL was missing and also space before target was missing too.

if (strlen($value) > 0)

$value = "<a href='http://".$value."'; target=_blank>".$value."</a>";

else

$value="";