Remove a specific character of plaintext with simple dom html - html-parsing

I have this code to retrieve some products on a website:
foreach($page1->find('.link_category') as $produit1)
echo $produit1->plaintext . '<br />';
I retrieve product with double quote ", i would like to replace it (the double quote)by nothing
thanks for help

foreach($page1->find('.link_category') as $produit1) {
$product = str_replace('"','',$produit1->plaintext);
echo $product;
}
I hope it works :)

Related

Get code between tags and generate youtube embed

I have some tekst and in the middle of article I put {youtube}IPtv14q9ZDg{/youtube}. How to make code which is between {youtube} generated in youtube embed
I use PHP, but there might be other options.
I filter the text for the key-words. Then take the 11 digit code and wrap it in a link tag. Works best in a "for loop".
This is one I use to find url's in my text and make them live. But you can modify it to do what you want by changing the "preg_match" setting.
function make_clickable($string) {
$string = preg_replace("/[\n\r]/"," <br /> ",$string);
$arr = explode(' ', $string);
foreach($arr as $key => $value){
if(preg_match('#((^https?|http|ftp)://(\S*?\.\S*?))([\s)\[\]{},;"\':<]|\.\s|$)#i', $value)){
$arr[$key] = "<a class=\"custome\" href='". $value ."' target=\"_blank\" class='link'>$value</a> ";
}
}
$string = implode(' ', $arr);
return $string;
}

new line for tooltip fetching values from the database

$price = mysql_result($result, $num, "drinks_shot"); $price2 = mysql_result($result, $num, "drinks_bottle");
$append = $clean_name.'<br> Per shot: Php'.$price.'<br> Per bottle: Php'.$price2.'.00'; $description = mysql_result($result, $num, "drinks_image"); echo "<td class='label'><img src='". mysql_result($result, $num, 'drinks_image')."' onclick='addtocart(". mysql_result($result, $num, 'drinks_id').")' class='masterTooltip' title= '".$append."'<br>";
if only i could make it display like
hennessy
price1
price2
i found similar posts regarding my problem but none of them are really working. Please help. :(
You want linebreaks inside a title="" tooltip? Instead of using <br>, use \n and make sure it's inside double (") quotes and not single quotes. Like so:
$append = $clean_name . "\n Per shot: Php" . $price . "\n ...";

Jquery Mobile data-autodividers

Is there a way to have the auto-dividers sort by last name?
I don't think it should have anything to do with the php code, but I thought I would include it for a reference below:
$result = mysql_query("SELECT * FROM `patients` WHERE `company_id` = " . $user_data['company_id'] . " ORDER BY `patient_lastname`");
while($row = mysql_fetch_array($result)) {
echo '<li>' . $row['patient_firstname'] . ' ' . $row['patient_lastname'] . '<span class="ui-li-count">DOB: ' . $row['patient_dob'] . '</span></li>';
}
Appreciate any help!
You can do the sorting in the front-end by selecting the list items and sorting them afterward. In the example below, instead of selecting the text content of the list items, you can select the last-name value.
var listContentArray = listViewInstance.find('li').not('.ui-li-divider').get();
listContentArray.sort(function (a, b) {
var first = $(a).text(),
second = $(b).text();
if (first < second) {
return -1;
}
if (first > second) {
return 1;
}
return 0;
});
Then you can destroy the content of the listViewInstance, re-append the elements in the listContentArray, and finally refresh the listView component.
You can download a fully functional example that does all of this at:
http://appcropolis.com/page-templates/autodividers/
Couldn't find a way to display Firstname then Lastname and autodivide by Lastname, so I just replaced the code with:
' . $row['patient_lastname'] . ', ' . $row['patient_firstname'] . '
which displays: "Lastname, Firstname" and autodivides by Lastname. It'll have to work for now.

Error message: Fatal error: Can't use function return > value in write context in

I am trying to run some code from a book. There appears to be a problem with the code.
Here is the error message:
Fatal error: Can't use function return
value in write context in
/Applications/MAMP/htdocs/Eclipse-Workspace/simpleblog/test.php
on line 24
Here is the code referenced in the message (starting on line 24)
if (!empty(trim($_POST['username']))
&& !empty(trim($_POST['email']))) {
// Store escaped $_POST values in variables
$uname = htmlentities($_POST['username']);
$email = htmlentities($_POST['email']);
$_SESSION['username'] = $uname;
echo "Thanks for registering! <br />",
"Username: $uname <br />",
"Email: $email <br />";
}
I would appreciate any help. Please let me know if I need to provide any more information
Thanks a lot guys. That was very fast. The solution works great.
The problem is that the empty() function needs to be applied only to direct variables.
For future reference:
The code is from 'PHP for Absolute Beginners' by Jason Lengstorf (2009), pages 90-91, Chapter 3, $_SESSION
corrected code:
//new - Created a variable that can be passed to the empty() function
$trimusername = trim($_POST['username']);
//modified - applying the empty function correctly to the new variable
if (!empty($trimusername)
&& !empty($trimusername)) {
// Store escaped $_POST values in variables
$uname = htmlentities($_POST['username']);
$email = htmlentities($_POST['email']);
$_SESSION['username'] = $uname;
echo "Thanks for registering! <br />",
"Username: $uname <br />",
"Email: $email <br />";
}
In short: The empty() function only works directly on variables
<?php
empty($foo); // ok
empty(trim($foo)); // not ok
i'd say, for the course of getting further with that book, just use a temporary variable
so change:
if (!empty(trim($_POST['username']))
to
$username = trim($_POST['username']);
if(!empty($username)) {
//....
Exactly your example is mentioned at the manual
Note:
empty() only checks variables as anything else will result in a parse error. In other words, the following will not work: empty(trim($name)).
Use a temporary variable, or just test against "empty string"
if (trim($foo) !== '') {
// Your code
}

Image link in jqgrid column

I want to display image link in a column in jqgrid with image name as querystring.The link should contain following path "Home\ShowImage?imageName=vlaue".
function jqGridFormatter(cell, options, row) {
return "Image";
}
Then you need to specify this formatter in colModel options for jqGrid, see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:custom_formatter.
You can move the image through xml or json in your url parameter like this:
$image = "<a href='#'><img src='folders/images/arrow.jpg' border='0' valign='middle' title='Edit something'><a>";
echo "<?xml version='1.0' encoding='iso-8859-1'?$et\n";
echo "<rows>"; echo "<page>".$page."</page>";
echo "<total>".$total_pages."</total>";
echo "<records>".$count."</records>"; // be sure to put text data in CDATA
echo "<row id='". $id."'>";
echo "<cell>". $image."</cell>";
echo "</row>";
}
echo "</rows>";
Please note that should be written as <a>

Resources