simple html dom and text - text

suppose that a simple html dom object includes the following
text1
<br />
<br />
<br />
text2
<br />
How can i get either of texts using simple html dom?

Just use plaintext to get text value from html.
$opts = array(
'http' => array(
'method' => "GET",
'header' => "Accept-language: en\r\n" .
"User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US;
rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6\r\n" .
"Cookie: foo=bar\r\n"
)
);
$context = stream_context_create($opts);
$html1 = new simple_html_dom();
$html1->load_file($url, false, $context);
$appName1 = $html1->find('tagname.classname or id', 0)->plaintext;
For class use (tagname.classname) and for id use (tagname#id) to get text.
$context is for set header for browser support if any website get mobile version so u can add header to get browser support content.

To grab all plain text elements, you can use the following:
$string="text1
<br />
<br />
<br />
text2
<br />";
$html = str_get_html($string);
$texts=$html->find('text');
foreach($texts as $elem_index => $text){
echo $elem_index."=>".$text."<br>";
}
Your output should look something like this:
0=>text1
1=>
2=>
3=> text2
In the foreach loop, you can obviously do whatever filtering you need to. For instance, if you're trying to find some text that matches a specific string, you can simply do:
if (trim($text) == "text2")
//do something
So, if you wanted to replace the found text, you could use:
if (trim($text) == "text2")
$texts[$elem_index]->innertext = "something else";
$html->save();
and $html will contain the new html.

With jquery try $(document.body).contents();
This should you a array of node with the text1 and text2 as text node.

Related

PHPMailer Embedded Image from attachment

I am the outsider for using script.
I am trying use AddEmbeddedImage and cid: to embed image from attachment, is that correct?? But failure...
Thank you very much for your help in advance !!!
$signature = $_POST['signature'];
$signatureFileName = uniqid().'.png';
$signature = str_replace('data:image/png;base64,', '', $signature);
$signature = str_replace(' ', '+', $signature);
$data = base64_decode($signature);
$file = 'signatures/'.$signatureFileName;
file_put_contents($file, $data);
$message='Subject: '.$_POST['subject'].'<br />
<img src="cid:'.uniqid().'.png"/> <br />
<img src="cid:'.uniqid().'"/> <br />
';
require "../phpmailer/class.phpmailer.php";
require "../phpmailer/setting.php";
$mail->Subject = "Image Form";
$mail->MsgHTML($message);
$mail->AddEmbeddedImage($file, uniqid());
You are calling uniqid() multiple times, and as the docs say, each time it will give you a new, random result, so your attachment CIDs will never match what's in your message content. Do it like this to ensure they match:
$cid = uniqid();
$message='Subject: ' . $_POST['subject'] . '<br />
<img src="cid:' . $cid . '"/> <br />';
$mail->addEmbeddedAttachment($file, $cid);

redirecting search result, form submit

in my index page I have this code to call search action:
$this->renderPartial('search');
and this is the search action code:
$criteria = new CDbCriteria();
if (isset($_GET['city'])) {
$q = $_GET['city'];
$criteria->compare('fileName', $q, true, 'OR');
$criteria->compare('tags', $q, true, 'OR');
$dataProvider = new CActiveDataProvider("Files", array('criteria' => $criteria));
$this->redirect('result', array('dataProvider'=>$dataProvider));
}
$dataProvider = new CActiveDataProvider("Files", array('criteria' => $criteria));
$this->render('search');
and this is the search view:
<form method="get">
<?php
$url = CHtml::normalizeUrl(array("files/search"));
$model = Files::model();
$c = new FilesController('view');
$this->widget('zii.widgets.jui.CJuiAutoComplete',array(
'model'=>$model,
'id'=>'autocomplete',
'attribute'=>$model->fileName,
'name'=>'city',
'source'=>$c->actionAutoComplete(),
// additional javascript options for the autocomplete plugin
'options'=>array(
'minLength'=>'1',
),
'htmlOptions'=>array(
'style'=>'height:20px;',
'placeholder'=>'search',
'value'=>'isset($_GET["city"]) ? CHtml::encode($_GET["city"]) : "" ',
),));
?>
<input type="submit" value="search" />
</form>
I want to show the search results in another view, so once clicked the search submit button I want to redirect to another view to show the results, but in this code the search result is shown in the index page.
so how to do it?
you can either set the url that you want your form to be send, like:
$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
'action' => Yii::app()->createUrl('anotherController/anotherView'),
'method' => 'post',
));
or you can redirect to another page after your done in index, like:
$this->redirect(array('anotherController/anotherView'));

Get data from previous page

I create a popup window using onclick="window.open()" the question is how can i get the data from previous page? here is my code :
<?php
include ("conn.php");
extract($_GET);
$applicantID = $_GET['applicantID'];
$sql = "SELECT * FROM applicant WHERE applicantID ='$applicantID'";
$query = mysql_query($sql);
$data = mysql_fetch_array($query);
echo $data['applicantID'];
?>
When i echo $data['applicantID']; it doesn't show any data.
I use this <input type="button" value="Check" onclick="window.open('checkstatus.php','popup','width=800,height=800,scrollbars=yes,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0'); return false" />
Why don't you use window.open('checkstatus.php?applicantID=something')? And retrieve it by $applicantID = $_GET['applicantID'] so that I hope it will work.

Custom predefined code template

I've been looking everywhere but I'm either blind or it's really not there.
I'm looking for some option to add some sort of code template to Dreamweaver (CS5.5) which I can access with some shortcode via the code hinting menu. In Zend (PHP IDE) you could define such code blocks like
$query = "";
$sql = mysql_query($query);
$result = mysql_fetch_assoc($sql);
and let Zend put them into your code when typing "qry" and hitting enter.
Is there such an option in Adobe Dreamweaver CS5.5?
I'we been looking for the same and found a solution. Try to add to your dreamweaver instalation path
"\Adobe Dreamweaver CS5\configuration\CodeHints\php_codehints.xml"
into to the section
<menugroup MMString:name="php/CORE" id="PHP_CORE"></menugroup>
following code:
<menu pattern="$query" doctypes="PHP_MySQL" displayrestriction="PHP_Script"
caseSensitive="true" icon="shared/mm/images/hintKeyword.png"
MMString:source="php/CORE" >
<menuitem label="mssql fetch //complete" value="="
SELECT * FROM
WHERE
";
$Qresult = mssql_query($query);
while ($Qdata = mssql_fetch_assoc($Qresult)) {
echo $Qdata[''];
};
" icon="shared/mm/images/hintMisc.gif"/>
</menu>
Now when you type $query to your code within PHP site, dreamweaver will offer you "mssql fetch //complete"
Analogically other code blocks. For example following:
<menu pattern="for" doctypes="PHP_MySQL" displayrestriction="PHP_Script"
caseSensitive="true" icon="shared/mm/images/hintKeyword.png"
MMString:source="php/CORE" >
<menuitem label="foreach()//complete" value="each ($arr as $k => $v) {
}" icon="shared/mm/images/hintMisc.gif"/>
<menuitem label="for()//complete" value=" ($i=0; $i<=$ ; $i++) {
};" icon="shared/mm/images/hintMisc.gif"/>
</menu>
<menu pattern="if" doctypes="PHP_MySQL" displayrestriction="PHP_Script"
caseSensitive="true" icon="shared/mm/images/hintKeyword.png"
MMString:source="php/CORE" >
<menuitem label="if()//complete" value=" ( ) {
}" icon="shared/mm/images/hintMisc.gif"/>
<menuitem label="if else//complete" value=" ( ) {
}
else {
}" icon="shared/mm/images/hintMisc.gif"/>
</menu>
I thing this solution works on Dreamweaver since CS versions, may be in MX too.
On the other site you can simply use SHIFT+F9 and define your own code block to paste.

How to send HTML email in drupal 6 using drupal_mail?

How to send HTML email in drupal 6 using drupal_mail ? How can I change HTML header to show email contents in HTML.
You can to set the header in hook_mail_alter()
<?php
hook_mail_alter(&$message) {
$message['headers']['Content-Type'] = 'text/html; charset=UTF-8; format=flowed';
}
?>
i know this may be late, but it may help others. Its better to use drupal_mail and then set the headers in hook_mail instead of hook_mail alter. an example would be like:
/*drupal_mail($module, $key, $to, $language, $params = array(), $from = NULL, $send = TRUE)
Lets say we call drupal_mail from somewhere in our code*/
$params = array(
'subject' => t('Client Requests Quote'),
'body' => t("Body of the email goes here"),
);
drupal_mail("samplemail", "samplemail_html_mail", "admin#mysite.com", language_default(), $params, "admin#mysite.com");
/*We now setup our mail format, etc in hook mail*/
function hook_mail($key, &$message, $params)
{
case 'samplemail_html_mail':
/*
* Emails with this key will be HTML emails,
* we therefore cannot use drupal default headers, but set our own headers
*/
/*
* $vars required even if not used to get $language in there since t takes in: t($string, $args = array(), $langcode = NULL) */
$message['subject'] = t($params['subject'], $var, $language->language);
/* the email body is here, inside the $message array */
$body = "<html><body>
<h2>HTML Email Sample with Drupal</h2>
<hr /><br /><br />
{$params['body']}
</body></html>";
$message['body'][] = $body;
$message['headers']['Content-Type'] = 'text/html; charset=UTF-8; format=flowed';
break;
}
If this is unclear to you, a complete tutorial on this can be found on My Blog
Hope this helps
JK

Resources