How to get file name and clean url [duplicate] - javascript

This question already has answers here:
Get only filename from url in php without any variable values which exist in the url
(13 answers)
Closed 4 years ago.
I have these urls and I need to remove the first part to get the file name:
http://isonex.ru/upload/iblock/ebd/ebdbd2a3961fc73170978ae4995b5a4b.jpeg
http://isonex.ru/upload/iblock/62a/62a5e49b20e498bfef00d81fa03403c8.jpeg
How can I clean the url to get only the file names?
For example:
ebdbd2a3961fc73170978ae4995b5a4b.jpeg
62a5e49b20e498bfef00d81fa03403c8.jpeg
c0004e9ab6e749b4bfc70d652722e966.jpeg

Since, you tagged PHP, you can use basename function.
<?php
echo basename("http://isonex.ru/upload/iblock/ebd/ebdbd2a3961fc73170978ae4995b5a4b.jpeg"),"\n";
echo basename("http://isonex.ru/upload/iblock/62a/62a5e49b20e498bfef00d81fa03403c8.jpeg");
OUTPUT:
ebdbd2a3961fc73170978ae4995b5a4b.jpeg
62a5e49b20e498bfef00d81fa03403c8.jpeg

Related

How to GET variables from URL and insert it within POST in JavaScript [duplicate]

This question already has answers here:
How can I get query string values in JavaScript?
(73 answers)
Closed 1 year ago.
I am new in PHP and javascript and need help with the following code
I want to get the value from browser URL that tag with "org" and use it in javascript; as example "http://localhost/nmt/index.php?org=table1" I want to put the "org" value inside the URL/ inside the POST $.post("ch1.php?org=table1", instead of table1 put the GET value
This is the part from code
$(document).ready(function () { showGraph1(); }); function showGraph1() { { $.post("ch1.php?org=table1", function (data) { console.log(data);
That If possible replace table1 with the value from URL
You can inject your variable into the javascript.
<script>
var data = <?php echo json_encode($_GET["org"]); ?>;
</script>
You also can get the url parameter directly from js.

how can i get the parameter using window.location.search.substring [duplicate]

This question already has answers here:
How can I get query string values in JavaScript?
(73 answers)
Closed 4 years ago.
I have this URL https://localhost/test.html?view=1111&project=1000.
How would i write java script function to fetch the variable project..?
A cool trick is to split your URL with project= and take the second element :
const url = "https://localhost/test.html?view=1111&project=1000"
console.log( url.split("project=")[1] )

How to read data between xml tags with attributes in javascript/ionic without using DOM/ActiveXObject? [duplicate]

This question already has answers here:
Parse XML using JavaScript [duplicate]
(2 answers)
Closed 5 years ago.
I simply need to extract some info between two tags, in this case, <wsse:BinarySecurityToken>
For example:
<wsse:BinarySecurityToken att1="abc" att2="cd3" att3="adfa">This is a text I need!!!===</wsse:BinarySecurityToken>
I tried
match = text.match(/<wsse:BinarySecurityToken[.*]>([^<]*)<\/wsse:BinarySecurityToken>/g)
does't work!
Or is there anything better than regex? I use angularJs 1
You want to do:
match = text.match(/<tag1.*>([^<]*)<\/tag1>/g)

How to Insert Javascript Variable to PHP Code [duplicate]

This question already has answers here:
javascript variable into php
(3 answers)
Closed 8 years ago.
i have php code like this
<?php
$queryitemkits="select item_id, cost_price, unit_price from items where item_id='JAVASCRIPTVARIABLE'";
$resultqueryitemkit = mysql_query($queryitemkits) or die('Query failed item kits!');
while($rowitem = mysql_fetch_assoc($resultqueryitemkit))
{
$itemcostprice=$rowitem['cost_price'];
$itemunitprice=$rowitem['unit_price'];
}
?>
and i have javascript variable named ui.item.value
how to insert that ui.item.value javascript variable to replace JAVASCRIPTVARIABLE in above PHP code?
Remember PHP is on the server, and the variable "JAVASCRIPTVARIABLE" in the client, you need to submit the variable to the server, also you need input validation, JAVASCRIPTVARIABLE it can be empty when is received on the server.

How to get the pathname in JS after the /? [duplicate]

This question already has answers here:
JavaScript - Get Portion of URL Path
(6 answers)
Closed 8 years ago.
If the current url is: "https://stackoverflow.com/questions/ask"
What's a good way to just get: "questions/ask" ?
You could use
window.location.pathname.substring(1)
You would use window.location.pathname
console.log(window.location.pathname.substring(1));
This would output everything after the first /

Categories