Using a str_replace within a php tag - str-replace

Can someone please help me with what I am doing wrong here. Quite a novice when it comes to PHP
Here is my code:
<?php echo $breadcrumb['text']; str_replace("<br />",""); ?>

I think the correct way of executing that is this.:
echo str_replace("<br />", "", $breadcrumb['text']);
In this case, you want to replace all br-tags with "" in the $breadcrumb['text'] variable.
Look at the documentation for that function here: http://php.net/manual/en/function.str-replace.php

If I understand:
<?php
$breadcrumb['text'] = "Something <br /> Next line but now on first <br />";
str_replace("<br />","", $breadcrumb['text']);
echo $bread;
?>

Related

result should be obtained as comma separated

My code for the slide looks like this in the static form.
<div id="demo-1" data-zs-src='["<?php echo base_url();?>assets/images/s1.jpg", "<?php echo base_url();?>assets/images/sd1.jpg", "<?php echo base_url();?>assets/images/slide7.jpg", "<?php echo base_url();?>assets/images/sd3.jpg"]' data-zs-overlay="dots">
<div class="demo-inner-content">
<h1><span>Tasty</span> & <span>Healthy</span></h1>
<p>For those who have taste for life.</p>
</div>
and when i change it into dynamic i changed my code like this
<?php foreach($slide1 as $ss){?>
data-zs-src='["<?php echo base_url();?>uploads/<?php echo $ss->image;?>" ]' alt=""
data-zs-overlay="dots">
<div class="demo-inner-content">
<h1><span>Tasty</span> & <span>Healthy</span></h1>
<p>For those who have taste for life.</p>
</div>
My problem is the slide will work only when comma is added after each image for that i thought to add implode function but its not working properly and my code with implode looks like this
<div id="demo-1" data-zs-src='[<?php foreach( $slides as $slide ){ $images="<?php echo base_url();?>uploads/<?php echo $slide->image;?>";
?>"<?php echo implode(',',$images);?>"<?php }?>]'
data-zs-overlay="dots">
<div class="demo-inner-content">
<h1><span>Tasty</span> & <span>Healthy</span></h1>
<p>For those who have taste for life.</p>
</div>
So you have to think about what it is you are trying to achieve here...
You seem to be trying to perform an implode on each string inside the foreach loop... Apart from the errors that would have been generated, it doesn't make sense to perform that in each loop. Its something you do after you have created the array entries... Implode works on arrays, not strings. It generates a string from an array.
Basically you are wanting to take an array of objects and want to convert those into a comma delimited string.
I'm not sure why you insist of putting ALL the code inside the HTML code where you want it to appear... I'd separate it out like this...
<?php foreach ($slides as $slide) {
$images[] = base_url('uploads/') . $slide->image;
} ?>
<div id="demo-1" data-zs-src='["
<?= implode(',', $images); ?>
"]'
data-zs-overlay="dots">
<div class="demo-inner-content">
<h1><span>Tasty</span> & <span>Healthy</span></h1>
<p>For those who have taste for life.</p>
</div>
Step 1: Create your Array of images
<?php foreach ($slides as $slide) {
$images[] = base_url('uploads/') . $slide->image;
} ?>
This can be done in your controller or in a helper but in your view is just as good. Depends on how you like to structure your code.
Step 2: Put the resulting string where you want it.
<div id="demo-1" data-zs-src='["
<?= implode(',', $images); ?>
"]'
data-zs-overlay="dots">
<div class="demo-inner-content">
<h1><span>Tasty</span> & <span>Healthy</span></h1>
<p>For those who have taste for life.</p>
</div>
You can refactor this even more but I have taken the first step in refactoring it so it hopefully makes sense to you.
NOTE: I have used <?= instead of <?php echo ( available since PHP 5.4.0) so if you are using something older than 5.4.0 stick with <?php echo.

iOS browser throws Phishing warning

We have a site, mysite.com, which links to another site of ours, mydemo.com.
The link is https://demouser:password#subdomain.mydemo.com, and in iOS, when users click on the link, because of the username and password. Below is the image :
Is there some possibility to tell the iOS browser that this is not a phishing attempt?
Rather than a direct link, use a PHP file with a redirect like this one
<?php function redirect($url, $statusCode = 302)
{
header('Location: ' . $url, true, $statusCode);
die();
}
$url = 'https://demouser:password#subdomain.mydemo.com';
redirect($url); ?>
If you need a dynamic link (different users, different link) use a PHP file like this with a form leading to it.
demo.php:
<?php function redirect($url, $statusCode = 302)
{
header('Location: ' . $url, true, $statusCode);
die();
}
$url = 'https://' . $_POST['user'] . ':' . $_POST['password'] . '#subdomain.mydemo.com';
redirect($url); ?>
and
login.htm
<form action='demo.php' method='post'>
Username <input type='text' name='user'><br>
Password <input type='password' name='password'><br>
<input type='submit' value='login'>
</form>

How to wrap input element inside div in ZF2

I am following this link.
In view I have
echo $this->formRow($product->get('name'));
and in source it is showing like
<label>Name of the product<input name="product[name]" required="required" type="text" value=""></label>
But I want like this
<div><label>Name of the product</label></div>
<div><input name="product[name]" required="required" type="text" value=""></div>
Maybe this question asked somewhere but I am not able to find it.
I am using php 5.6.
EDIT:
According to the answer I was able to solve this issue.Following the documentation in this link. I have issue in this part
echo $this->formCollection($product->get('categories'));
I tried like this
echo "<div>".$this->formLabel($this->get('categories'))."</div>";
echo "<div>".$this->formInput($this->get('categories'))."</div>";
But it throws fatal error.
Catchable fatal error: Object of class Zend\Form\View\Helper\FormLabel could not be converted to string in /opt/lampp/htdocs/zend2/module/Test/view/test/index/testform.phtml on line 39
How can I fix this?
instead of $this->formRow, You can use the below code and can separate the label and input both.
echo $this->formLabel($form->get('name'));
echo $this->formInput($form->get('name'));
It will output this:
<label>Name of the product</label>
<input name="product[name]" required="required" type="text" value="">
And then you can use the div tag in echo. So here is what you want:
echo "<div>".$this->formLabel($form->get('name'))."</div>";
echo "<div>".$this->formInput($form->get('name'))."</div>";

PHP Simple HTML DOM Parser - error

I have this code:
<?php
header('Content-type: text/plain; charset=utf-8');
include('simple_html_dom.php');
$html = file_get_html('http://test.com/');
$class = $html->find("thisisatest", 0)->innertext;
echo $class;
?>
Error page:
<br />
<b>Notice</b>: Trying to get property of non-object in <b>C:\xamp\htdocs\test\test.php</b> on line <b>6</b><br />
Why do sometimes everything works fine and sometimes I am getting an error?
It is probably useful to print the html to see what u are getting. The url be getting redirected. Probably helpful to use curl to get more consistent results and do error check

Get Textarea Value with Simpe HTML Dom

i using simple_html_dom.php
how to get textarea value if the website has used bad tag.
the textarea tag already closed before </textarea> like input tag.
Textarea HTML like below:
<textarea name="xxx" id="xxx" />this is value</textarea>
When i use this function, i dont get anything
$textarea = $html->find("textarea[name=xxx]");
$contents = $textarea->innertext;
echo $contents;
how to get 'this is value' using simple_html_dom.php or other alternative?
Thank you
Well, my previous comment won't work in this case, I'll leave it for info though...
Another approach is to clean it up before parsing it with simple_html_dom using Tidy extension. But it seems not to be working here either...
A last approach I can think of, and if this is your only problematic case, is to use regex to get what you want:
Using <textarea.*?name="xxx".*?id="xxx".*?\/>([^<]+)<\/textarea> ==> RegEx DEMO
The output will be in group one of the resulting array $match. Check this working code:
$input = <<<_DATA_
<textarea name="xxx" id="xxx" />this is value</textarea>
_DATA_;
$pattern = '/<textarea.*?name="xxx".*?id="xxx".*?\/>([^<]+)<\/textarea>/';
preg_match($pattern, $input, $match);
var_dump($match)
Working DEMO
It is easy to get the value of a Teaxtarea in javascript:
<script type=text/javascript>
function getValueTextarea()
{
var vl=document.getElementById("tx").value;
alert(vl);
}
</script>
<body>
<textarea id="tx">Value Of Textarea</textarea>
<input id="button" value="Get Value" onclick="getValueTextarea()">
</body>

Resources