This script is something i wrote during work, as I often need to do this (concatenate strings via multiple lines so it's clearer). Hopefully you guys like it.
convert html to php code, more of less
def htmlToPHP(varname, html):
if type(varname) != str:
raise TypeError("varname must be string.")
if type(html) == list or type(html) == tuple:
for line in html:
line = addslash(line)
print "%s .= \"%s\\n\";" % (varname, line)
elif type(html) == str:
htmlToPHP(varname, html.split("\n"))
else:
raise TypeError("html must be string or list of strings")
def addslash(string):
string = string.strip()
i = 0
while i < len(string):
index = string.find('"', i)
if index != -1:
string = string[0:index] + "\\" + string[index:]
else:
break
i = index + 2
return string
t = '''<a href="test.php">some link</a>
<h1 class="small">Something</h1>'''
htmlToPHP("$txt", t)
# outputs:
# $txt .= "<a href=\"test.php\">some link</a>\n";
# $txt .= "<h1 class=\"small\">Something</h1>\n";
TrustyTony
888
pyMod
Team Colleague
Featured Poster
ultimatebuster
14
Posting Whiz in Training
Dcurvez
0
Junior Poster in Training
GoodLuckChuck
0
Junior Poster in Training
TrustyTony
888
pyMod
Team Colleague
Featured Poster
Dcurvez
0
Junior Poster in Training
ultimatebuster
14
Posting Whiz in Training
TrustyTony
888
pyMod
Team Colleague
Featured Poster
ultimatebuster
14
Posting Whiz in Training
TrustyTony
888
pyMod
Team Colleague
Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.