Ho uno script che analizza un URL. Se la query contiene l'utente e la password, recupera questo.
Vorrei, pertanto, per mantenere il PHP query, se necessario.
Add-Type -AssemblyName System.Web
$url = "http://toto.site:8080/user/password12349876toolong/2716?checkedby:toto.net"
$uri = [System.Uri]$url
$query = $uri.Query
$IPTVhost = $uri.Host
$IPTVport = $uri.Port
$Segments = $uri.Segments.TrimEnd('/')
$proto = $uri.Scheme
$ParsedQueryString = [System.Web.HttpUtility]::ParseQueryString($uri.Query)
if(!$query) {
if ($Segments[1].TrimEnd('/') -eq "live"){
$username = $Segments[2].TrimEnd('/')
$password = $Segments[3].TrimEnd('/')
}
else
{
$username = $Segments[1].TrimEnd('/')
$password = $Segments[2].TrimEnd('/')
}
}
else {
$username = $ParsedQueryString['username']
$password = $ParsedQueryString['password']
}
cls
if (!($url -like '\?checkedby\:'))
{
echo "this is a chekedby url"
$filter = $url.TrimEnd("\?checkedby\:toto.net")
echo "filter : $filter"
}
echo "url: $url"
echo "query: $query"
echo "host: $IPTVhost"
echo "port: $IPTVport"
echo "segment: $Segments"
echo "proto: $proto"
echo "username: $username"
echo "password: $password"
Vorrei filtro di una stringa di caratteri quando inserisco un URL nel mio script (che si trova spesso nella query ma non sempre).
So che si inizia sempre con "? Checkedby:"
o "& checkedby:"
ed è sempre alla fine dell'url.
Problematica: la catena è variabile, può essere:
http://toto.com:8080/get.php?username=toto&password=toto&checkedby:titi.com
o
http://toto.com/1234/4321/5678?checkedby:anyone.xyz
o
http://toto.com/1234/4321/5678?master.m3u8&checkedby:anyelse.to
o questa schifezza :
http://toto.com:8080/get.php?username=toto&password=toto&type=output.ext?checkedby:titi.com
Ho provato diversi metodi con TrimEnd ma non aiuta. L'unica cosa che funziona è l'esatta espressione come:
$filter = $url.TrimEnd("\?checkedby\:toto.net")
ma che non funziona (e questo è normale) con un url che termina con:
&checkedby:another.com.
Quindi, domanda :
Come rimuovere tutto ciò che inizia con:
&checkedby:
o
?checkedby:
Grazie.