Jump to content

skippt

New Members
  • Posts

    9
  • Joined

  • Last visited

skippt's Achievements

Member

Member (2/5)

0

Reputation

  1. Hi, I'm trying to replace <p> tags and replace it with a contenteditable div. $newpost = str_replace("<p>", "<div contenteditable=\"true\"><p>", $post); This code works fine however I'm using javascript setInterval to periodically update to a database through ajax and while it doesn't conflict with javascript when I refresh the page it inserts a second string replace. eg. On first refresh it enters <div contenteditable="true"><p> On second refresh it enters <div contenteditable="true"><div contenteditable="true"><p> On third refresh it enters <div contenteditable="true"><div contenteditable="true"><div contenteditable="true"><p> I've tried replacing the <p> with <P> or <p class="paragraph"> and str_replace instead of str_ireplace but I still get the same result. Does anyone know of any way I can only have it replace once?
  2. Hi, I'm working on trying to make a string in a textarea bold by inserting bold tags. The script I have can be found below: http://jsfiddle.net/28Bc5/1/ The script will insert bold tags but I'm trying to work out a way in which I can remove the bold tags when highlighting. It would have to check whether bold tags are wrapped around the string and then remove them. I'd imagine it would work something like this: If only part of the bold string is highlighted, insert a </b> tag at the beginning and insert of </b> tag at the end of the string. If left side of the bold string is highlighted, remove <b> tag from beginning and move it to the end of the highlighted string. If right side of the bold string is highlighted, remove </b> tag from end and move it to the beginning of highlighted string. Can anyone teach me how I would do this please?
  3. Hi, I'm currently trying to build a script that will allow two divs to sit next to each other and move when resized. The code I have so far is here: http://jsfiddle.net/7BSrL/6/ I would like it the second div to move to the right when the first div is resized and if the div gets too large for the container, the second div should move below the first div. Could anyone teach me how to do this please?
  4. Hi, I'm doing some web scraping and at the end I end up with an array. $list[] = array('link' => $link, 'types' => $types); Sometimes name is empty so I end up with an array like this: Array ( [0] => Array ( [link] => [types] => Array ( ) ) [1] => Array ( [link] => [types] => Array ( ) ) [2] => Array ( [link] => http://example.com [types] => Array ( ) ) ) Is there any way I'd be able to get rid of all the values that are empty and so each new link starts at key 0? Thanks
  5. URLs look something like this: http://mysite.com/index.php?controller=1&method=2&arg=3 with the .htaccess added it looks like: http://mysite.com/1/2/3 Now if I want to go to a method within an index class I would have to do this: http://mysite.com/index/about My question is how would I be able to access the about page without putting /index/ before it? I've tried adding this to my .htaccess file: RewriteRule ^(.*)$ index.php which does work since I have to go to /app/view/css/style.css/ to access my stylesheets it breaks them. How would I do this without breaking my stylesheets? This is my .htaccess file: Options +Indexes +FollowSymLinks +Multiviews RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/(.*)$ index.php?url=$1&method=$2 [QSA,L] RewriteRule ^(.*)$ index.php Thanks
  6. Hi, I'm currently using this tutorial to guide me and I'm trying out some of the examples but I don't really understand it. The version of PHP I'm using is 5.3.27 so I'm using this compatibility library. Okay, so my code for registering a user is below: $options = array('cost' => 11); $password = password_hash($password, PASSWORD_BCRYPT, $options); It takes the password inserted into a form, then I take the outputted $password and enter it into the database. For the password verify bit, I have: $hash = '$2y$11$6SXlwd2iKZcYuz9guncYXe39/x6lUR5u4EfJQr.qKhEPAuXFgLWeS'; if (password_verify($password, $hash)) { echo 'Password is valid!'; } else { echo 'Invalid password.'; } That works fine, except I need to grab the hash from the database. When I try to match that to the password entered into a form to the hash from the database, it comes up with invalid password. I think I'm doing this completely wrong. Can anyone help me out please?
  7. Hi, I have an array like this: array(2) { [0]=> object(stdClass)#6 (6) { ["id"]=> string(1) "1" ["title"]=> string(36) "Weather Forecast" ["link"]=> string(18) "link" ["price"]=> string(4) "0.83" ["country"]=> string(2) "GB" ["network"]=> string(7) "network" } [1]=> object(stdClass)#7 (6) { ["id"]=> string(1) "2" ["title"]=> string(33) "Media Player" ["link"]=> string(18) "link" ["price"]=> string(4) "0.71" ["country"]=> string(2) "GB" ["network"]=> string(7) "network" } } I would like to get it so that I can retrieve selected keys in each row. For example, so it will output the first ["title"], then the second ["title"] and ignore the rest of the information without calling them individually. The same for the links and so on. So, I be left with a grid like: Weather Forecast | link | 0.83 Media Player | link | 0.71 Thanks.
  8. I'm trying to build a simple mvc framework to understand. I've heard advice about rolling you own framework but I'd rather learn by playing with some basic examples since diving into using pre existing frameworks without understanding everything seems daunting to me. So, I have a controller, model and view. In my database file I'm able to retrieve data using $result[1]->title as an example, but I'd like to have that information passed to the view (which is basically just my template file). I'm not really sure how to do this, I've tried a couple of methods and googled, but I've got conflicting answers. I'd appreciate it if anyone could point me in the right direction and maybe give advice for best practices for mvc structure since I got a lot of conflicting answers on that. I've attached some of the code I'm using below. Controller.php <?php class Controller { private $model; private $load; private $name; public function __construct($model, $load) { $this->model = $model; $this->load = $load; } public function index() { $name = 'view'; $this->load->view($name); $this->model->index(); } } Database.php <?php class Database { function getData() { $username = 'username'; $password = '****'; try { $dbh = new PDO('mysql:host=localhost;dbname=db_name', $username, $password); } catch (PDOException $e) { echo $e->getMessage(); } //PDO Class $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); $dbh->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER); $sth = $dbh->query("SELECT * FROM posts"); $result = $sth->fetchAll(PDO::FETCH_OBJ); //print_r($result); //echo $result[1]->title; } } Model.php <?php class Model { public function __construct(){ $this->string = "MVC + PHP = Awesome!"; } public function index() { } }
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.