Framför allt denna raden ska ni kolla på: height="""& getImgHeight("/upload/textbilder/$1")&"""
jag försöker få utan höjden på det:
getImgHeight funktionen:
Function getImgHeight(img)
Dim myImg, fs
SET fs= CreateObject("Scripting.FileSystemObject")
IF fs.fileExists(Server.MapPath(img)) THEN
SET myImg = loadpicture(Server.MapPath(img))
getImgHeight = round(myImg.height / 26.4583)
SET myImg = nothing
ELSE
getImgHeight=""
END IF
SET fs=Nothing
END Function
men problemmet är att den vill inte...skirver jag namnet på bilden istället för $1 så funkar det...men inte annars...
Replace(Innlegg,getref("f"))
function f(r,o,m,a)
f = "<img src=""upload/textbilder/"& o &""" height="""& getImgHeight("/upload/textbilder/"& o &"") &""" alt="""& o &""" class=""text_bild"" />"
end function
Jag får inte riktigt rätt på det...
jag kanske ska förklara lite mer.
Det är när jag skriver ut en text så ligger det bildnamn i den texten.
Jag hämtar sedan ut bilderna från en speciell mapp.
Hela koden just nu:
<%
Innlegg = Replace(Server.HTMLEncode(rs("info")),vbCrLf,"<br />")
With New RegExp
.Global=True
.IgnoreCase=True
.Pattern="\[u\]([\w\W]*?)\[/u\]"
Innlegg=.Replace(Innlegg,"<h5>$1</h5>")
.Pattern="\[b\]([\w\W]*?)\[/b\]"
Innlegg=.Replace(Innlegg,"<strong>$1</strong>")
.Pattern="\[i\]([\w\W]*?)\[/i\]"
Innlegg=.Replace(Innlegg,"<em>$1</em>")
.Pattern="\[p\]([\w\W]*?)\[/p\]"
Innlegg=.Replace(Innlegg,"<div class=""box"">$1</div>")
.Pattern="\[r\]([\w\W]*?)\[/r\]"
Innlegg=.Replace(Innlegg,"<em class=""red"">$1</em>")
.Pattern="\[g\]([\w\W]*?)\[/g\]"
Innlegg=.Replace(Innlegg,"<em class=""green"">$1</em>")
.Pattern="\[bl\]([\w\W]*?)\[/bl\]"
Innlegg=.Replace(Innlegg,"<em class=""blue"">$1</em>")
.Pattern="\[c\]([\w\W]*?)\[/c\]"
Innlegg=.Replace(Innlegg,"<p class=""center"">$1</p>")
.Pattern="\[www\]([\w\W]*?)\[/www\]"
Innlegg=.Replace(Innlegg,"<a href=""http://$1"" title=""$1"">$1</a>")
.Pattern="\[list\]([\w\W]*?)\[/list\]"
Innlegg=.Replace(Innlegg,"<ul class=""text_list""><li>$1</li></ul>")
dim a
a = inlegg
set r = new regexp
with r
.pattern = "\[img](.*?)\[/img]"
a = .Replace(a,getref("f"))
end with
set r = nothing
response.write a
function f(r,o,m,a)
f = "<img src=""upload/textbilder/"& o &""" height="""& getImgHeight("/upload/textbilder/"& o &"") &""" alt="""& o &""" class=""text_bild"" />"
end function
End With
Response.write(Innlegg)
%>
Denna koden ger syntax error på function f(r,o,m,a)
<%
Innlegg = Replace(Server.HTMLEncode(rs("info")),vbCrLf,"<br />")
With New RegExp
.Global=True
.IgnoreCase=True
.Pattern="\[u\]([\w\W]*?)\[/u\]"
Innlegg=.Replace(Innlegg,"<h5>$1</h5>")
.Pattern="\[b\]([\w\W]*?)\[/b\]"
Innlegg=.Replace(Innlegg,"<strong>$1</strong>")
.Pattern="\[i\]([\w\W]*?)\[/i\]"
Innlegg=.Replace(Innlegg,"<em>$1</em>")
.Pattern="\[p\]([\w\W]*?)\[/p\]"
Innlegg=.Replace(Innlegg,"<div class=""box"">$1</div>")
.Pattern="\[r\]([\w\W]*?)\[/r\]"
Innlegg=.Replace(Innlegg,"<em class=""red"">$1</em>")
.Pattern="\[g\]([\w\W]*?)\[/g\]"
Innlegg=.Replace(Innlegg,"<em class=""green"">$1</em>")
.Pattern="\[bl\]([\w\W]*?)\[/bl\]"
Innlegg=.Replace(Innlegg,"<em class=""blue"">$1</em>")
.Pattern="\[c\]([\w\W]*?)\[/c\]"
Innlegg=.Replace(Innlegg,"<p class=""center"">$1</p>")
.Pattern="\[www\]([\w\W]*?)\[/www\]"
Innlegg=.Replace(Innlegg,"<a href=""http://$1"" title=""$1"">$1</a>")
.Pattern="\[list\]([\w\W]*?)\[/list\]"
Innlegg=.Replace(Innlegg,"<ul class=""text_list""><li>$1</li></ul>")
.Pattern = "\[img](.*?)\[/img]"
Innlegg=.Replace(Innlegg,getref("f"))
End With
Response.write(Innlegg)
function f(r,o,m,a)
f = "<img src=""upload/textbilder/"& o &""" height="""& getImgHeight("/upload/textbilder/"& o &"") &""" alt="""& o &""" class=""text_bild"" />"
end function
%>
Och här har du funktionerna som tar widthen och heighten
Function getImgWidth(img)
Dim myImg, fs
SET fs= CreateObject("Scripting.FileSystemObject")
IF fs.fileExists(Server.MapPath(img)) THEN
SET myImg = loadpicture(Server.MapPath(img))
getImgWidth = round(myImg.width / 26.4583)
SET myImg = nothing
ELSE
getImgWidth="Fel!"
END IF
SET fs=Nothing
END Function
Function getImgHeight(img)
Dim myImg, fs
SET fs= CreateObject("Scripting.FileSystemObject")
IF fs.fileExists(Server.MapPath(img)) THEN
SET myImg = loadpicture(Server.MapPath(img))
getImgHeight = round(myImg.height / 26.4583)
SET myImg = nothing
ELSE
getImgWidth="Fel!"
END IF
SET fs=Nothing
END Function
Orsaken till detta är att få sidan godkänd i validatorn som kräver widht och height på alla bilder.
...tyder på att det finns mer kod att visa. Ligger With-blocket innanför något annat kontrollblock? Som jag skrev innan tror jag ej att funktioner kan definieras i sådana block, vilket är fallet om du använder ovanstående kod.
Hej
Om jag tar min ursprungliga kod:
Innlegg=.Replace(Innlegg,"<img src=""upload/textbilder/$1"" height="""& getImgHeight("/upload/textbilder/$1")&""" alt=""$1"" class=""text_bild"" />")
och byter ut $1 i height="""& getImgHeight("/upload/textbilder/$1")&""" till namnet på bilden så fungerar både getImgheight och getImgwidth så funktionerna fungerar.
Men den verkar inte skicka rätt in i funktionen om jag använder $1.
Function getImgWidth(img)
Dim myImg, fs
SET fs= CreateObject("Scripting.FileSystemObject")
IF fs.fileExists(Server.MapPath(img)) THEN
SET myImg = loadpicture(Server.MapPath(img))
getImgWidth = round(myImg.width / 26.4583)
SET myImg = nothing
ELSE
getImgWidth="Fel!"
END IF
SET fs=Nothing
END Function
Function getImgHeight(img)
Dim myImg, fs
SET fs= CreateObject("Scripting.FileSystemObject")
IF fs.fileExists(Server.MapPath(img)) THEN
SET myImg = loadpicture(Server.MapPath(img))
getImgHeight = round(myImg.height / 26.4583)
SET myImg = nothing
ELSE
getImgHeight=img
END IF
SET fs=Nothing
END Function
function f(r,o,m,a)
f = "<img src=""/maxi/upload/textbilder/"& o &""" width="""& getImgWidth("/maxi/upload/textbilder/"& o &"") &""" height="""& getImgHeight("/maxi/upload/textbilder/"& o &"") &""" alt="""& o &""" class=""text_bild"" />"
end functio
Anledningen till att jag använder getref() är att det annars verkar vara svårt att läsa av captures ($1...$n). Ibland vill man ju faktiskt kunna skicka in dem i en funktion (getImgHeight/-Width i ditt fall).
'f' var bara ett exempel från min sida. Du kan ju döpa om funktionen till något mer passande namn.
Glöm inte att använda acceptera som slutgiltigt svar.
267 ms totalt · 4 externa anrop · v20260731065814-full.7d626504