How get text right floating and right as a center?
$text = "The epic finale that will live foreve";
$newtext = wordwrap($text, 20, "<br />\n");
echo $newtext;
Just guessing what is the question:
$text = "The epic finale that will live foreve";
$newtext = wordwrap($text, 20, "<br />\n");
echo '<div style="float: right; width:50%; text-align: center;">'.$newtext.'</div>';
Related
Help please to get a correct solution of my task.
I have this dropdown (it looks like dropdown) with code:
<div class="jcf-select-drop jcf-select-jcf-hidden jcf-unselectable" style="position: absolute; top: 1331px; width: 376.125px; left: 285.75px;">
<div class="jcf-select-drop-content">
<span class="jcf-list jcf-scroll-active">
<span class="jcf-list-content" style="max-height: 369px; overflow: auto;">
<ul>
<li>
<span class="jcf-option" data-index="0">Afghanistan</span>
</li>
<li>
<span class="jcf-option" data-index="218">USA</span>
</li>
And simple test:
let countryTest = $$("span.jcf-select.jcf-unselectable").first();
let USA = $("body > div.jcf-select-drop.jcf-select-jcf-hidden.jcf- unselectable > div > span > span > ul > li:nth-child(217) > span");
countryTest.click();
USA.click();
I need to select USA, but have an error "Failed: element not interactable". I can get Afghanistan, but not USA.. I tried
browser.actions().mouseMove(USA).click().perform();
but it isn't help.
Can I somehow click on USA-element using data-index? Or what is correct way to choose the element?
And how is there a way to make shorter the element(by.css), because it's too long..
I am assuming that the dropdown contains a full list of countries. As such, USA will not be high on the list (number 218 it looks like). Because your dropdown will only display a limited amount of countries at once, USA is hidden. Most dropdowns allow text to be entered to search for a country. This also limits the matches to all be displayed on the screen. You can then click on USA (although its index may have changed)
Example
let countryTest = $$("span.jcf-select.jcf-unselectable").first();
let USA = $("body > div.jcf-select-drop.jcf-select-jcf-hidden.jcf-unselectable > div > span > span > ul > li:nth-child(217) > span");
//keep in mind USA selector will likely have changed after you do your search
countryTest.click();
countryTest.sendKeys('USA'); //likely will be a different element that you have to send keys to
USA.click();
Try the below one
const countryTest = element(by.cssContainingText('spna.jcf-list-content>ul>li>span', 'USA'));
So countryTest.click() selects USA from the dropDown.
hope it helps you.
Assuming you already solved clicking a parent element that displays the dropdown, have you tried the following?:
If you have just those 2 options:
var USA = element.all(by.css('.jcf-list-content ul li span')).last();
countryTest.click();
USA.click();
If the dropdown has more options (USA being 218?):
var USA = element.all(by.css('.jcf-list-content ul li span')).get(218);
countryTest.click();
USA.click();
You can try with the 'span' at the end, or removing it. I'm not sure which one will work.
Ultimately, try something like this:
var USA = element(by.cssContainingText('li', 'USA'));
countryTest.click();
USA.click();
Hope it helps.
guys i use TCPDF library for my php server and i want to create a label with width:57mm and height:32mm
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetPrintHeader(false);
$pdf->SetPrintFooter(false);
$pdf->AddPage('L', array(57,32));
$pdf->SetFont('dejavusans');
$html ="
<table class='domi'>
<tbody >";
for($i=0; $i<$rows; $i++){
$style=' style="font-size:'.$fontsize[0][$i].'px"';
if($bold[0][$i]===0){
$html2a[$i] = "<tr><td".$style.">".$content_line[$i]."</td></tr>";
} else {
$html2a[$i] = "<tr><td".$style."><b>".$content_line[$i]."</b></td></tr>";
}
$html2b .= $html2a[$i];//$pdf->GetStringWidth($html2a[$i])." ";
}
$html3 = "</tbody>
</table>";
$pdf->writeHTMLCell($w=55, $h=2, $x='1', $y='1', $html.$html2b.$html3, $border=1, $ln=1, $fill=0, $reseth=false, $align='C', $autopadding=true);
$pdf->Output($_SERVER['DOCUMENT_ROOT'] . 'Site/labels/label'.$id.'.pdf', 'FI');
1st of all it prints the contents fine from the database in A4 size etc but all i want is to create and save the pdf document in the label size width:57mm and height:32mm!!! https://i.stack.imgur.com/kQ8Be.png
as you see, I've marked with 1-5 numbers the actual data and the rest are marked with questionmarks!! I dont understand why of course.
2nd when i change the line $pdf->AddPage('L', array(57,32)); to $pdf->AddPage('L', array(57,57)); the label is created but i have an empty space in the bottom-right corner + it doesnt have the 32x57 size!!! https://i.stack.imgur.com/XgEWU.png
thanks in advance!!!
it seems that i had missconfigured my TCPDF library...
the simple solution that i came up was to put this line
$pdf->SetAutoPageBreak(true, 0);
after this
$pdf->SetFont('dejavusans');
and the result was perfect!!!
https://i.stack.imgur.com/hGwyR.png <-perfectly configured label
https://i.stack.imgur.com/khs9v.png <-wrongly configured label
but in my case it perfect for the job!!! all i want is to preview the result before saving (i mean saving the wrong configuration and then update the base until the configuration is good!!)
I spent about 2 hours trying to make a blending of 2 codes work, and feeling the weakness of my code skills, I am reaching out here for some help.
I think the problem lies in the single/double quotes. I tried many, many times to reformat the quotations (and both ways ie reformatting both scripts to accommodate each other).
The image (which should be linked) is added to the page in the functions.php -- the image is path/image.png in this example:
! is_admin() && add_filter( 'the_content', function( $content )
{
if( in_the_loop() ) // <-- Target the main loop
{
$prepend = "<div style='color:#808080 ; border:1px solid #909090 ; border-radius:5px; float:left; padding-top:1px;'> <**img src='/path/image.png' alt='Tweet this' style='margin-bottom: -4px; '**>Tweet this </div> ";
$content = $prepend . $content;
}
return $content;
}, 9 );
This is the link -- When the user clicks the image, I want them to access this link:
<a href='https://twitter.com/share?url=<?php echo $post_url ?>&text=<?php echo $post_title ?>' onclick='window.open(this.href,"popupwindow", "width=800,height=500,left=200,top=5,scrollbars,toolbar=0,resizable"); return false;' Target='_blank' >twitter</a>
What I want to end up with is: Click the image on the page, (it opens the Twitter link,) user gets to Tweet (share) the post they are on on Twitter.
So user clicks image (path/image.png) and opens link (twitter.com...etc).
Still not sure of anything: you should realize that your question lacks clarity.
Notably because you don't say where $post_url and $post_title comes from, nor explain what are $prepend and $content, and don't explain at all your function's use and context.
But I'll talk about what I believe to have understood.
Your goal seems to result in this kind of HTML part:
<div style="color:#808080; border:1px solid #909090; border-radius:5px; float:left; padding-top:1px;">
<a href="https://twitter.com/share?url=the-post_url&text=the-post_title"
onclick="window.open(this.href,'popupwindow','width=800,height=500,left=200,top=5,scrollbars,toolbar=0,resizable'); return false;"
target="_blank">
<img src="/path/image.png" alt="Tweet this" style="margin-bottom:-4px;">
Tweet this
</a>
</div>
(you'll notice that I've returned back to arbitrary give precedence to double-quotes, which is the most standard choice)
Say we call $div, $a, and $img the source main components, to output the desired block we simply have to write something like:
echo $div . $a . $img . 'Tweet this </a></div';
I suppose the issue you're reporting comes from you have to define those components as strings, while they already include simple and double quotes.
So the answer is using the PHP heredoc syntax:
Heredoc text behaves just like a double-quoted string, without the double quotes. This means that quotes in a heredoc do not need to be escaped, but the escape codes listed above can still be used. Variables are expanded, but the same care must be taken when expressing complex variables inside a heredoc as with strings.
And the components definition should look like:
$div = <<<EOT
<div style="color:#808080; border:1px solid #909090; border-radius:5px; float:left; padding-top:1px;">
EOT;
$a = <<<EOT
<a href="https://twitter.com/share?url=$post_url&text=$post_title" onclick="window.open(this.href,'popupwindow','width=800,height=500,left=200,top=5,scrollbars,toolbar=0,resizable'); return false;" target="_blank">
EOT;
$img = <<<EOT
<img src="/path/image.png" alt="Tweet this" style="margin-bottom:-4px;">
EOT;
In fact many other variations may be considered, notably directly using a unique variable for the whole part...
EDIT:
Here is a working whole snippet, after integrating a value for $post_urland $post_title and corrected a typo in echo...:
$post_url="the-post-url";
$post_title="the-post-title";
$div = <<<EOT
<div style="color:#808080; border:1px solid #909090; border-radius:5px; float:left; padding-top:1px;">
EOT;
$a = <<<EOT
<a href="https://twitter.com/share?url=$post_url&text=$post_title" onclick="window.open(this.href,'popupwindow','width=800,height=500,left=200,top=5,scrollbars,toolbar=0,resizable'); return false;" target="_blank">
EOT;
$img = <<<EOT
<img src="/path/image.png" alt="Tweet this" style="margin-bottom:-4px;" />
EOT;
echo $div . $a . $img . 'Tweet this </a></div>';
Im trying to sign an image with GD.
I have a line of text, which may look like this: "This is a very long line of text"
If I use 60th font, it wont fit in my image, so I need some how do wordwrap
Now I'm using loop that is doing word wrap limited by number of symbols and adding text to image line by line..
$words = explode(" ", $text);
if (strlen($words[0]) > 20)
$output = substr($words[0], 0, 20);
else {
$output = array_shift($words);
while (strlen($output . " " . $words[0]) <= 20) {
$output .= " " . array_shift($words);
}
}
$text = $str2 = substr($text, strlen($output));
list($left,, $right) = imageftbbox($font_sizet, 0, $font_path, $output);
$width = $right - $left;
$leftx = (740 - $width) / 2;
$topy = (560 + $i * 30);
imagettftext($img, $font_sizet, 0, $leftx, $topy, $white, $font_path, $output);
The problem with this script is that if the first letters are going to be "WWWWWWWWWWW", the image will fit only 10 symbols... and if first letters are going to be "llllllllllll" the text will look short.
The width of text I cant determine by using this line:
list($left,, $right) = imageftbbox( $font_sizet, 0, $font_path, $output);
$width = $right - $left;
<- i think that somehow I can use this $width in my
loop to compare with maxlength
How can I change limiting by number of symbols to limiting by number of pixels (lets say, I want the line to be no longer than 300px)?
I have made a website.It worked all fine during the whole development and testing phase of over 20 days during which I viewed the pages always in firefox and they were all fine.But today suddenly I encountered a problem with firefox. The table data are not centered and the borders are not rounded as they used to be earlier.But they are all fine in Google Chrome..You can view the screenshots :
Mozilla Firefox (It not used to be like this !)
Google Chrome
Please tell me how to fix it..I have cleared all the cache and session of firefox but still its the same
UPD
Ok so I am providing the codes as well:
The Php code (only snippet) of the table
$result = mysql_query("SELECT username,rating,contests,rank from users order by (rating) desc limit 10");
echo '<table id="problems">
<thead><tr>
<th colspan="3" align="center" ><font color="red" ><h2>Top Rated</h2></font></th>
</tr></thead>
<tr>
<th>#</th>
<th>Username</th>
<th >Rating </th>
</tr>';
while($row = mysql_fetch_array($result))
{
require_once("color_gen.php");
require_once("rankings.php");
ranker_rater();
$color=ColorGen($row['rating'],$row['contests']);
$uname=$row['username'];
$rank=$row['rank'];
echo "<tr>";
echo "<td>" . $rank. "</td>";
echo '<td><font color="'.$color.'">'.$uname.'</font></td>';
echo "<td>" . $row['rating'] . "</td>";
echo "</tr>";
}
echo "</table>";
And the corresponding CSS
#problems
{
text-align:centre;
border:solid;
border-width:2px;
border-color:#CCC;
width : 100%;
}
#problems th,td
{
padding: 4px;
font-weight: normal;
border:solid;
border-width:1px;
border-color:#CCC;
font-size: 15px;
color: #039;
//background: #b9c9fe;
text-align:center;
}
Know that different browsers have different default functions. This is the fundamental manner in which I attack this problem. Google chrome typically is more kind to web developers and is better at correcting errors. But, if you want something to be consistent throughout all browsers, ensure that the values are stated explicitly.
Problem 1 - Text not centered: I notice that in your CSS, your first line assigns text-align to "centre." The internet was founded by Americans, and all browsers will support the American spelling of "center." The problem is probably that Firefox does not support the British spelling of the word. I won't know until its tried, though.
Problem 2 - Corners not rounded: Since I am not a very skilled web developer, this is a problem I do not know how to solve. However, I've found a blog post by someone who does.