Deprecated: Function ereg() & ereg_replace() - ereg

i'm actually using a script i've used for years before and when i put it in my website, i got the error "Deprecated: Function ereg() & ereg_replace()". I'm actually unable to understand how to modify the ereg() things in preg() things. If someone is able to able, i'll appreciate!
Here is my code:
// couleur
$t=str_replace("[/color]", "</span>", $t);
$regCouleur="\[color= ?(([[:alpha:]]+)|(#[[:digit:][:alpha:]]{6})) ?\]";
$t=ereg_replace($regCouleur, "<span style=\"color: \\1\">", $t);
// taille des caractères
$t=str_replace("[/size]", "</span>", $t);
$regCouleur="\[size= ?([[:digit:]]+) ?\]";
$t=ereg_replace($regCouleur, "<span style=\"font-size: \\1px\">", $t);
// lien
$regLienSimple="\[url\] ?([^\[]*) ?\[/url\]";
$regLienEtendu="\[url ?=([^\[]*) ?] ?([^]]*) ?\[/url\]";
if (ereg($regLienSimple, $t)) $t=ereg_replace($regLienSimple, "\\1", $t);
else $t=ereg_replace($regLienEtendu, "\\2", $t);
// mail
$regMailSimple="\[email\] ?([^\[]*) ?\[/email\]";
$regMailEtendu="\[email ?=([^\[]*) ?] ?([^]]*) ?\[/email\]";
if (ereg($regMailSimple, $t)) $t=ereg_replace($regMailSimple, "\\1", $t);
else $t=ereg_replace($regMailEtendu, "\\2", $t);
// image
$regImage="\[img\] ?([^\[]*) ?\[/img\]";
$regImageAlternatif="\[img ?= ?([^\[]*) ?\]";
if (ereg($regImage, $t)) $t=ereg_replace($regImage, "<img src=\"\\1\" alt=\"\" border=\"0\" />", $t);
else $t=ereg_replace($regImageAlternatif, "<img src=\"\\1\" alt=\"\" border=\"0\" />", $t);
// Video
$regVidSimple="\[video\] ?([^\[]*) ?\[/video\]";
$regVidEtendu="\[video ?=([^\[]*) ?] ?([^]]*) ?\[/video\]";
if (ereg($regVidSimple, $t)) $t=ereg_replace($regVidSimple, "<p style=\"text-align: center;\"><object style=\"background-color: rgb(255, 255, 204); background-position: 50% 50%;\" data=\"\\1\" type=\"application/x-shockwave-flash\" height=\"190\" width=\"240\"><param name=\"src\" value=\"\\1\"></object></p>", $t);
else $t=ereg_replace($regVidEtendu, "<iframe title=\"YouTube video player\" width=\"240\" height=\"190\" src=\"\\1\" frameborder=\"0\" allowfullscreen>\\2</iframe>", $t);
Thanks for your answers !

Try this:
$regCouleur="/\[color=\s+(([[:alpha:]]+)|(#[[:digit:][:alpha:]]{6}))\s+\]/";
$t=preg_replace($regCouleur, "<span style=\"font-size: \\1px\">', $t);
By the way, could you please add a source and an expected string?

Related

Word HTML page break won't work if using mso footer

I want to add a footer to my HTML-generated Word .doc files, but if I use the code that's out there I lose my page break control.
For example:
In the header I have 'mso-footer: f1;' in the #page Section 1 tags
In the header I have:
p.MsoFooter, li.MsoFooter, div.MsoFooter
{
margin:0in;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
tab-stops:center 3.0in right 6.0in;
font-size:12.0pt;
}
Just after my normal HTML table stuff I've inserted:
strHtmlFooter = strHtmlFooter & "<div style='mso-element:footer' id=f1>"
strHtmlFooter = strHtmlFooter & "<p class='MsoFooter'>"
strHtmlFooter = strHtmlFooter & "<span style='mso-tab-count:2'>Fred Smith</span>"
strHtmlFooter = strHtmlFooter & "</p>"
strHtmlFooter = strHtmlFooter & "</div>"
and then after this I have the line:
strHtmlFooter = strHtmlFooter & "<BR CLEAR='ALL' STYLE='mso-special-character:line-break;page-break-before:always'>"
If I run the above I get a MS Word doc with a footer on, but none of my page breaks works.
If I take out the page footer div then the page breaks come back.
Any ideas how I can have both??
Thanks

<td> specific formatting will change background color but not border color

this is driving me up the wall.
I have a loop that spits a table back from php into my html page. grabs the last 30 'messages' posted into a DB Table along with some other things. I have a dynamic color coding based on what the user sets as their message background color. Works fine. When logged in, I want to show a different border color on that user's messages. i.e. my messages have different border color when I am logged in. It works if i use my if statement to change the background color, but not the border color.
This Works and changes the background color:
$bgcol = 'bgcolor="#ecb3ff">'
if($uid == $userid){ $bgcol = 'bgcolor="white">';}
echo "<tr><td width='66%' " . $bgcol . $msg . "</td></tr>";
This Doesn't Work:
$bgcol = 'bgcolor="#ecb3ff">'
if($uid == $userid){ $bgcol = 'borderColor="black" ' . $bgcol;}
echo "<tr><td width='66%' " . $bgcol . $msg . "</td></tr>";
How about using inline style like this :
$bgcol = 'background-color:#ecb3ff;'
if($uid == $userid){ $bgcol = 'border-color:black; '. $bgcol;}
echo "<tr><td width='66%' style='". $bgcol ."'>". $msg ."</td></tr>";
Have you tried using a class eventually ?
$class = '';
if($uid == $userid){ $class = 'bg1';}
echo "<tr><td width='66%' class='". $class ."'>". $msg ."</td></tr>";
CSS
td {
background-color: #ecb3ff;
border-bottom: 2px solid white;
}
td.bg1 {
background-color: black;
border-color: black;
}

How can I allow user to upload own PDF and have it displayed?

I have a website for school where every teacher is going to have a page. Each teacher's page will have a spot for them to upload a PDF. I want this to then show in a viewer on the page so students see the Viewer when they access it.
How would I code into the website allowing the user to upload a PDF and not have it replaced until somebody else uploads a PDF?
so far I have the code to upload a document.
<form method="POST" enctype="multipart/form-data" action="fup.cgi">
File to upload: <input type="file" name="upfile"><br/>
Notes about the file: <input type="text" name="note"><br/>
<br/>
<input type="submit" value="Press"> to upload the file!
</form>
How can I get it to go into a viewer below? and that it saves until replaced.
1 - First thing you are not able to upload file to server but your form action is claiming to use CGI,
2 - Second i cant really get what you want but the following code can upload files to server its in PHP and otherthing are you using SQL or what Database are you using it seems you also need database
<?php
set_time_limit(0);
if(!is_dir("uploads")){
$uploadDir = mkdir("uploads");
}
$allowedExts = array("pdf", "docx", "doc");
$extension = end(explode(".", $_FILES["file"]["name"]));
if ((($_FILES["file"]["type"] == "application/pdf")
|| ($_FILES["file"]["type"] == "application/vnd.openxmlformats-officedocument.wordprocessingml.document")
|| ($_FILES["file"]["type"] == "application/msword"))
&& ($_FILES["file"]["size"] < 200000000000000)
&& in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
if (file_exists("/uploads/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"/uploads/" . $_FILES["file"]["name"]);
echo "Stored in: " . "/uploads/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>
Do you want to display pdf thumb, icon, or read the pdf

Photo Resize when loading... PHP photo from server

I'm wondering if anyone could provide me with some advice on where I went wrong. I'm trying to get a photo to resize when loaded in a DIV but the photo keeps taking it's own dimensions. Does anyone have any idea why my code isn't working? Thank you in advance!
if($row['coverphoto'] === NULL){
echo"<li>";
echo"<img src='images/slider-4.jpg'>";
echo "<div class='banner'>Customize Your Banner!</div>";
echo "</li>";
}
else{
echo "<li>";
echo "<img style='height:auto; width:auto; max-width:1025px; max-height:503px;' src='/coverphotos/" . $row['coverphoto'] . "'/><br />";
echo "<div class='banner'>Customize Your Banner!</div>";
echo "</li>";
}
?>
Try this,
else{
echo "<li>";
echo "<div style="width:50px;height:50px;"><img style='height:50px; width:50px;' src='/coverphotos/" . $row['coverphoto'] . "'/></div><br />";
echo "<div class='banner'>Customize Your Banner!</div>";
echo "</li>";
}
If it is not worked means, please check your, css file
<li>
styles. May that style makes this mistake.

href syntax : is it okay to have space in file name

it has always been my practice that when ever i use images i name them like
walls_ico , bu_hover
so when i give paths they go like
<img src="images/walls_ico.ico" />
<img src="buttons/bu_hover.png" />
UNTIL now when i am on a project where users upload files...
i was wondering is it okay to have spaces between file and folders name like
<img src="buttons/bu hover.png" />
The src attribute should contain a valid URL. Since space characters are not allowed in URLs, you have to encode them.
You can write:
<img src="buttons/bu%20hover.png" />
But not:
<img src="buttons/bu+hover.png" />
Because, as DavidRR rightfully points out in his comment, encoding space characters as + is only valid in the query string portion of an URL, not in the path itself.
Quoting HTML5 to back Frederic that spaces are not allowed:
http://www.w3.org/TR/html5/links.html#attr-hyperlink-href:
The href attribute on a and area elements must have a value that is a valid URL potentially surrounded by spaces.
The definition of "valid URL" points to: http://url.spec.whatwg.org which defines URL code points https://url.spec.whatwg.org/#url-code-points:
The URL code points are ASCII alphanumeric, "!", "$", "&", "'", "(", ")", "*", "+", ",", "-", ".", "/", ":", ";", "=", "?", "#", "_", "~", and code points in the ranges U+00A0 to U+D7FF, U+E000 to U+FDCF, U+FDF0 to U+FFFD, U+10000 to U+1FFFD, U+20000 to U+2FFFD, U+30000 to U+3FFFD, U+40000 to U+4FFFD, U+50000 to U+5FFFD, U+60000 to U+6FFFD, U+70000 to U+7FFFD, U+80000 to U+8FFFD, U+90000 to U+9FFFD, U+A0000 to U+AFFFD, U+B0000 to U+BFFFD, U+C0000 to U+CFFFD, U+D0000 to U+DFFFD, U+E1000 to U+EFFFD, U+F0000 to U+FFFFD, U+100000 to U+10FFFD.
The spec then uses the term URL code points on various parts of the parsing algorithm as:
If c is not the EOF code point, not a URL code point, and not "%", parse error.
for the scheme, authority, relative path, query state and fragment states: so the entire URL.
If you are using PHP
then find out this code
$result = mysqli_query($con,$sql);
//echo $ip."<br />";REGEXP
//echo $name."<br />";
echo "<table border=2px style='border-radius=20px;' align=center><tr>
<th>Document ID</th>
<th>Document Name Type</th>
<th>Download Documents</th>
</tr>";//<th>Project Document Type</th>
while($row = mysqli_fetch_array($result)) {
$path1=$row['FOLDERNAME'] .'/'. $row['FILENAME'] .'.'. $row['DOCTYPE'];
$path=str_replace(" ", '%20', $path1);
echo "<tr>";
echo "<td>" . $row['DocID'] . "</td>";
// echo "<td>" . $row['PROJDOCTYPE'] . "</td>";Thank you. Your Apple ID is now ready for use.
echo "<td>" . $row['DOCNAME'] . "</td>";
echo '<td><a href=Tender/'.$path.'>'.$row['DOCNAME'].'</a></td>';
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
<body>
<img src="file:///C|/Documents and Settings/All Users/Documents/My Pictures/Sample Pictures/Water lilies.jpg"
</body>
spaces will be allowed only when you are working in local hosts