Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
How to make JS popup window inside echo line?
I have this line but the popup not work :
echo '<td> Edit</td>';
then I check the link location on status bar :
javascript:popWin(edit.php?id=12)
as what I learn before it should be single quote inside the popWin(), but I have no clue to solve this..
To place a literal singlequote in your echo use backslash to escape it:
echo '<td> Edit</td>';
Just replace this echo for this:
echo "<td> Edit</td>";
When you use double quotes, you can use simple quotes inside the echo without escaping it. (\)
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
How to replace the specific string only using one replace instead of two?
const formattedUrl = url.replace('flashget://', '').replace('&abc','')
What I have tried: (Not Working)
const formattedUrl = url.replace(/flashget:\/\/ | &abc/g, '').replace('&abc','')
Example
Input Url: flashget://W0ZMQVNIR0VUXWh0dHA6Ly93d3cuZm9yZWNlLm5ldC93aW43LnJhcltGTEFTSEdFVF0=&abc
Formatted Url: W0ZMQVNIR0VUXWh0dHA6Ly93d3cuZm9yZWNlLm5ldC93aW43LnJhcltGTEFTSEdFVF0=
Take out the spaces around the |
This is my attempt:
https://regex101.com/r/eFO7Eh/2
Search Regex:
flashget:\/\/(.*)\&.*$
Replace term:
$1
Just pay attention to the fact that this is a different logic and requires handling capture groups.
remove the space before and after the or |. it will work.
let url = "flashget://W0ZMQVNIR0VUXWh0dHA6Ly93d3cuZm9yZWNlLm5ldC93aW43LnJhcltGTEFTSEdFVF0=&abc"
const formattedUrl = url.replace(/flashget:\/\/|&abc/g, '');
console.log(formattedUrl);
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
Are there additional quotation marks in Php, and JavaScript besides "..." and '...' in the case I need to nest them?
(The Alt+Number would be useful)
For example a Php echo:
echo "
onClick='changeImage('example.jpg');'
";
I know I could escape the quotation marks , but I am wondering if there are another "level" of them that can be nested.
Javascript
You are in luck, in ES2015 specs, javascript now allows template literals using back ticks.
console.log(`hello "world!" I'm doing well :)`);
PHP
Use Nowdocs. Don't use Heredocs unless you want to evaluate php code inside the string.
Note: someone already answered this, but I'll just reiterate to contain a whole solution.
echo <<<'STR'
`hello "world!" I'm doing well :)`
STR;
Don't use Heredocs
echo <<<STR
`hello "world!" I'm doing well :)`
STR;
Or
echo <<<"STR"
`hello "world!" I'm doing well :)`
STR;
Difference is the single quoted name. This is a Heredoc. It will evaluate PHP code denoted by ${expression} in your string.
Don't use back ticks
In PHP backticks will be evaluated as a shell command and return the output of said shell command.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
i have string which is
testVariable--423h33c7uhyga5tjk
now i want to replace the above string with
testVariable
by using javascript replace function.
Use String#split method.
console.log(
'testVariable--423h33c7uhyga5tjk'.replace('--')[0]
)
Or with String#replace method.
console.log(
'testVariable--423h33c7uhyga5tjk'.replace(/--.*/, '')
// or including multiline
// .replace(/--[\s\S]*/, '')
)
While Pranav's method work, if you really need/Want to use the replace function, you could use regex:
var variable = 'testVariable--423h33c7uhyga5tjk';
console.log(variable.replace(/--.+$/, ''));
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I'm building my output text looping a JSON object using JavaScript. Everything is working fine until I come to the part where I need to add an ID number to an image URL. My images are stored in a database and I am using an ASHX handler to load the image however what I end up with is not exactly what I need.
My code that I need to end up with is ~/ImageHandler.ashx?id=35
but what I get is ~/ImageHandler.ashx?id='35'. Single quotes around the ID.
I know it is the syntax of " and "".
What I have tried is
myOutput += "<img src ='~/ImageHandler.ashx?id='" + ID + class='person-image'></img>"
and every combination that does not work.
If I remember correctly I need some combination of triple single quote or double quotes something or some combination of the both. ID is an integer that is being read from a JSON object.
Thanks in advance
You can add double quotes using the escape character \
myOutput += "<img src=\"~/ImageHandler.ashx?id=" + ID + "\" class=\"person-image\"></img>"
This will append
<img src="~/ImageHandler.ashx?id=35" class="person-image"></img>
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am confused why onclick is not wokring
Code1:
onclick="return clicked('35','http://www.google.com');"
Code2:
onclick='return clicked('35','http://www.google.com');'
If i used code1 onclick works fine but not with code2
thnx
Because you're breaking out of the onclick too soon, since you use single quotes for multiple things. The first one doesn't break since you can have single quotes in double quotes. If you use the second approach, escape the single quotes in the function call.
It's because of ' and " characters. If you open a " and want to put another string inside you need to use ' or it will close the first one.
That's why the code1 works, you start the string with ", then you use ' to specify parameters so the string isn't closed.
In code2, you start the string with ' and then use ' again to specify parameters. So the string you started is closed in the middle of you onclick statement.
code2 would work with :
onclick='return clicked("35","http://www.google.com");'
If you use single quotes for HTML attributes, you need to use double quotes for the Javascript arguments:
onclick='return clicked("35","http://www.google.com");'
Otherwise the browser is confused and thinks the attribute value is only return clicked(